AngularJS 指令控制器和要求

AngularJS directive controller and require

如何在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);
         }
      };
  }

使用 'require' 得到 ngModelControllerSelectBoxController:

  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]);
         }
      };
  }