Jim*_*ane 1 angularjs angularjs-directive
我正在使用ng-style在我的一个指令中传递样式.
像这样:
<my-component ng-style="test()" ng-model="message"></my-component>
Run Code Online (Sandbox Code Playgroud)
指令:
myModule.directive('myComponent', function(mySharedService) {
return {
restrict: 'E',
controller: function($scope, $attrs, mySharedService) {
$scope.test = function(){
console.log(1)
};
$scope.$on('handleBroadcast', function() {
$scope.message = 'Directive: ' + mySharedService.message;
});
},
replace: true,
template: '<input>'
};
});
Run Code Online (Sandbox Code Playgroud)
为什么test函数调用了2次?
| 归档时间: |
|
| 查看次数: |
2004 次 |
| 最近记录: |