scope重定义

 

.directive('myAttr', function() {
    return {
        restrict: 'E',
        scope: {
            customerInfo: '=info'
        },
        template: 'Name: {{customerInfo.name}} Address: {{customerInfo.address}}<br>' +
                  'Name: {{vojta.name}} Address: {{vojta.address}}'
    };
});

 

 

directive中的几个属性:

 

  1. restrict
    E: 表示该directive仅能以element方式使用,即:<my-dialog></my-dialog>
    A: 表示该directive仅能以attribute方式使用,即:<div my-dialog></div>
    EA: 表示该directive既能以element方式使用,也能以attribute方式使用

  2. :transclude:你的directive可能接受页面上的其他html内容时才会用到,建议你先去掉该参数。有些高阶了。

  3. scope:当你写上该属性时,就表示这个directive不会从它的controller里继承$scope对象,而是会重新创建一个。

  4. templateUrl:你的directive里的html内容

  5. link:可以简单理解为,当directive被angular 编译后,执行该方法

posted @ 2016-02-19 10:23  广林  阅读(207)  评论(0编辑  收藏  举报