测试案例

.directive('testDirective', function() {
return {
restrict: 'E',
template: '<p>Hello {{number}}!</p>',
controller: function($scope, $element){
$scope.number = "controller:"+$scope.number;
},
link: function(scope, el, attr) {
scope.number = "link:"+scope.number;
},
compile: function(element, attributes) {
return {
pre: function preLink(scope, element, attributes) {
scope.number = "compile: pre:"+scope.number;
},
post: function postLink(scope, element, attributes) {
scope.number = "compile: post:"+scope.number;
}
};
}
}
});

controller先运行,compile后运行,link不运行

将上例中的compile注释掉,controller先运行,link后运行,link和compile不兼容

controller,link,compile不同的更多相关文章

  1. angularjs link compile与controller的区别详解,了解angular生命周期

     壹 ❀ 引 我在 angularjs 一篇文章看懂自定义指令directive 一文中简单提及了自定义指令中的link链接函数与compile编译函数,并说到两者具有互斥特性,即同时存在link与c ...

  2. 了解 : angular controller link ng-init 顺序

    controller 会先跑,接着是view 里的ng-init,最后是link (指令里的). 所有在指令里如果用link去拿$attr,会有拿不到ng-init想setup的值

  3. directive 指令一

    什么是Directive Directive将一段html,js封装在一起,形成一个可以复用的独立个体,具有特定的功能.angularjs中的指令通常是比较小的组件,它相当于是给我们提供了一些公共的自 ...

  4. angularJS directive中的controller和link function辨析

    在angularJS中,你有一系列的view,负责将数据渲染给用户:你有一些controller,负责管理$scope(view model)并且暴露相关behavior(通过$scope定义)给到v ...

  5. Directive Controller And Link Timing In AngularJS

    I've talked about the timing of directives in AngularJS a few times before. But, it's a rather compl ...

  6. Vue源码详细解析:transclude,compile,link,依赖,批处理...一网打尽,全解析!

    用了Vue很久了,最近决定系统性的看看Vue的源码,相信看源码的同学不在少数,但是看的时候却发现挺有难度,Vue虽然足够精简,但是怎么说现在也有10k行的代码量了,深入进去逐行查看的时候感觉内容庞杂并 ...

  7. $compile

    <html ng-app="compile"> <head> <script src="http://apps.bdimg.com/libs ...

  8. controller 和 指令 通讯方法

    在 angular 中我们经常会使用多个 controller 和 指令 他们拥有各自的 $scope , 这就产生了跨$scope调用的问题. 有几种常见的方法来可以使用. 方法一 : 指令 req ...

  9. angular $compile的使用

    在写前端js时,经常会动态创建标签放入文本元素中: 比如:var strDiv='<div>new create element</div>'; $(strDiv).appen ...

  10. 指令<AngularJs>

    对于指令,可以把它简单的理解成在特定DOM元素上运行的函数,指令可以扩展这个元素的功能. 首先来看个完整的参数示例再来详细的介绍各个参数的作用及用法: angular.module('myApp', ...

随机推荐

  1. 用C语言实现ipv4地址字符串是否合法

    用程序实现ipv4地址字符串是否合法,主要考察的是C字符串的操作. 搜索了下,网上没有特别好的实现,自己实现了下,见笑于大家,请指正. #include <stdio.h> #includ ...

  2. POJ 3660 Cow Contest (最短路dijkstra)

    MPI Maelstrom 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/G Description BIT has recen ...

  3. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  4. linux下查看端口的占用情况

    前提:首先你必须知道,端口不是独立存在的,它是依附于进程的.某个进程开启,那么它对应的端口就开启了,进程关闭,则该端口也就关闭了.下次若某个进程再次开启,则相应的端口也再次开启.而不要纯粹的理解为关闭 ...

  5. Erp:原料投入产出报表

    USE [ChangHongWMS612]GO /****** Object: StoredProcedure [dbo].[st_WMS_RptMaterialInOutDaily] Script ...

  6. eclipse 安装scons

    http://www.sconsolidator.com/update  Installation To use SConsolidator, you first have to install SC ...

  7. Intel® RealSense™ SDK Architecture

    In this article, we highlight some of the key changes that you can expect to see in the Intel RealSe ...

  8. python的一些总结3

    好吧 刚刚的2篇文章都很水.. 这篇 也是继续水 在 templates 右键新建 html 文件:如 index.html (输入以下代码) <!DOCTYPE html> <ht ...

  9. 检测Insert、Capslock、NumLock、ScrollLock状态键的状态

    unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...

  10. iOS开发——实用篇&提高iOS开发效率的方法和工具

    提高iOS开发效率的方法和工具 介绍 这篇文章主要是介绍一下我在iOS开发中使用到的一些可以提升开发效率的方法和工具. IDE 首先要说的肯定是IDE了,说到IDE,Xcode不能跑,当然你也可能同时 ...