我有一些自定义指令,我已经绑定了ng模型和ng更改指令。
示例:
<custom-directive ng-model="users" ng-change="changed()">
</custom-directive>指令在执行后包含一些输入,文本区域等。我想要执行函数绑定到ng-change,changed()时,总是在这个输入中发生变化时,文本区域。
我可以从指令ng-change或link执行controller吗?
例如,就像这样:
.directive('customDirective', function () {
return {
restrict: 'E',
replace: true,
require: 'ngModel',
templateUrl: 'src/template.html',
link: function (scope, elem, attrs, ngModel) {
executeNgChange();
}
};
})发布于 2016-01-13 13:41:02
您应该能够使用ng-change的作用域函数表达式绑定在您的指令中绑定函数
.directive('customDirective', function () {
return {
restrict: 'E',
replace: true,
require: 'ngModel',
scope: {
change: '&ngChange'
}
templateUrl: 'src/template.html',
link: function (scope, elem, attrs, ngModel) {
scope.change(); // or use ng-change="change()" in your directive template
}
};
})我自己还没有测试过这个,但希望它能帮到你。
https://stackoverflow.com/questions/34767842
复制相似问题