[英]How to access angularJS controller as variables?
如何將控制器的值定義為自定義指令鏈接函數中的元素?
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
});
}
});
app.directive('myDirective',function(){
return{
require:'ngModel, ^myCtrl',
link:function(scope,elements,ctrls){
var d = ctrls[1].disable
});
}
});
內部鏈接函數寫為scope.ctrl.disable以訪問禁用值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.