pio*_*rek 5 angularjs angularjs-directive
我创建了一个简单的指令:
angular.module("foo").directive('bar',function(){
return {
...
template:
'<div> \
<div ng-hide="param1.length == 0 && param2...">...</div> \
<input ng-show="param1.length == 0 && param2..." .../> \
</div>',
scope: {
param1: '=',
param2: '='
}
};
});
Run Code Online (Sandbox Code Playgroud)
但是模板中有一个复制的复杂逻辑,所以我想把它提取到一个函数中,然后从模板中调用该函数.我在哪里可以放这样的功能,我该如何调用它?我是否必须创建专用控制器?
在链接功能中:
return {
...,
template: '<div><div ng-hide="foo()">...</div></div>',
link: function(scope) {
scope.foo = function() {
return scope.param1.length == 0 && ...;
};
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1539 次 |
| 最近记录: |