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中的几个属性:
-
restrict
E: 表示该directive仅能以element方式使用,即:<my-dialog></my-dialog>
A: 表示该directive仅能以attribute方式使用,即:<div my-dialog></div>
EA: 表示该directive既能以element方式使用,也能以attribute方式使用 -
:transclude:你的directive可能接受页面上的其他html内容时才会用到,建议你先去掉该参数。有些高阶了。
-
scope:当你写上该属性时,就表示这个directive不会从它的controller里继承$scope对象,而是会重新创建一个。
-
templateUrl:你的directive里的html内容
-
link:可以简单理解为,当directive被angular 编译后,执行该方法
本文来自博客园,作者:广林,转载请注明原文链接:https://www.cnblogs.com/guanglin/p/5200025.html
浙公网安备 33010602011771号