测试案例

.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. JSF 2 outputText example

    In JSF 2.0 web application, "h:outputText" tag is the most common used tag to display plai ...

  2. Spring MVC MultiActionController example

    In Spring MVC application, MultiActionController is used to group related actions into a single cont ...

  3. jquery easyui的方法参数

    1.form 表单的参数有:submit,validate,clear,load 2.submit 例如: $('#goods-add').form('submit', { url : url, on ...

  4. java tools: jmap

    SYNOPSIS jmap [ option ] pid click here to see detail DESCRIPTION jmap prints shared object memory m ...

  5. poj3041

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12162   Accepted: 6620 Descri ...

  6. AxWindowsMediaPlayer创建、添加播放列表(C#)

    // 创见打开对话框对象实例            OpenFileDialog openFileDialog = new OpenFileDialog(); //设置为可以打开多个文件        ...

  7. Netty笔记

    1 基本介绍 Bootstrap Netty应用程序通过设置 bootstrap(引导)类开始,该类提供了一个用于应用程序网络层配置的容器.Bootstrap有两种类型,一种是用于客户端的Bootst ...

  8. nginx缓存优先级(缓存问题者必看)

    接触nginx的兄弟或多或少都有遇到缓存问题,要么是nginx为什么不缓存,要么就是nginx缓存很快就失效等等问题,在网上找了一遍nginx缓存优先级的文章,大家可以参考下. 架构图client端  ...

  9. mysql5.5主从配置

    mysql主从同步# 一:mysql数据库的主从 mysql数据库5.5之后的版本和5.5以前的版本数据库主从存在差异,这里是针对数据库5.5之后的配置. 1.主库编辑my.cnf(linux的my. ...

  10. contiki-main.c 一 打印观察 <contiki学习之五>

    说明: 本文依赖于 contiki/platform/native/contiki-main.c 文件. 在项目工程目录下的hello-world.c 文件里面,有许多的宏,但没有最关键的main() ...