如何在Link函数中获取ngModel和SelectBoxController的实例?
指令
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);
}
};
}
答案 0 :(得分:1)
使用'要求'获得ngModelController
和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]);
}
};
}