Reputation: 2137
How to get instances of ngModel and SelectBoxController in Link function?
Directive
angular
.module('directives.selectBox', [])
.directive('selectBox', selectBox);
function selectBox() {
return {
restrict : 'E',
require : ['ngModel'],
scope : {
list : '=',
},
replace : true,
templateUrl : 'common/directives/selectBox/selectBox.html',
controller : SelectBoxController,
link: function(scope, element, attrs, controllers) {
console.log(controllers);
}
};
}
Upvotes: 1
Views: 39
Reputation: 52847
Use 'require' to get both the ngModelController
and SelectBoxController
:
function selectBox() {
return {
restrict : 'E',
require : ['ngModel','selectBox'],
scope : {
list : '=',
},
replace : true,
templateUrl : 'common/directives/selectBox/selectBox.html',
controller : SelectBoxController,
link: function(scope, element, attrs, controllers) {
console.log(controllers[0]);
console.log(controllers[1]);
}
};
}
Upvotes: 1