angularjs 指令

内置指令 及使用方法:

**replace 替换 **


**html模板写法 **

<hello><div>这里被替换没有了</div></hello>

指令写法

var myModule = angular.module(“myModule”,[]) 
myModule.directive(“hello”,function(){
     return {
          restrict:’AE’,
          replace:”true”,
          template:”<div>hello world </div>" 
     }
})

transclude 指令内部包含有元素的情况下指定该元素在指令元素的嵌套位置 很重要的功能,可以通过指令互相嵌套


html模板写法

  <hello><div>这里是指令内部内容</div></hello> 

指令写法

var myModule = angular.module(“myModule”,[])
myModule.directive(“hello”,function(){
     return {
          restrict:’AE’,
           transclude:”true”,
          template:”<div>hello world <div ng-tranclude></div></div>" 
 }
})

scope的绑定策略


@ 把当前属性作为字符串来传递。你还可以绑定来自外层scope的值。在属性值中插入{{}}即可。
= 与父scope中的属性进行双向绑定
& 传递一个来自父scope的函数,稍后调用

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容