如何将控制器的值定义为自定义指令链接函数中的元素?
HTML
<div ng-controller="myCtrl as ctrl">
<input type="text" ng-model=ctrl.inputvalue" my-directive/>
<button value="submit" ng-disabled="ctrl.disable"/>
</div>
JS
app.controller('myCtrl',function(){
var vm = this;
vm.inputValue = 'Qwerty';
});
app.directive('myDirective',function(){
return{
require:'ngModel',
link:function(scope,elements,ngModelCtrl){
//How to access ng-diasbled value here
});
}
});
答案 0 :(得分:1)
app.directive('myDirective',function(){
return{
require:'ngModel, ^myCtrl',
link:function(scope,elements,ctrls){
var d = ctrls[1].disable
});
}
});
答案 1 :(得分:1)
内部链接功能写为 scope.ctrl.disable 以访问禁用值。