Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access angularJS controller as variables?

Tags:

angularjs

How to define the value for controller as elements inside custom directive link function?

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
        });
    }    
});
like image 810
User1 Avatar asked Apr 22 '26 08:04

User1


1 Answers

Inside link function write as scope.ctrl.disable to access the disable value.

like image 105
Eftakhar Avatar answered Apr 25 '26 05:04

Eftakhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!