Angularjs $ decorate指令控制器

时间:2017-04-27 09:45:57

标签: javascript angularjs angularjs-directive angular-material

我试图装饰Angular Material指令并且对Controller原型函数有疑问:



$provide.decorator('mdChipsDirective', ['$delegate', '$controller', function($delegate, $controller) {
  var directive = $delegate[0];
  var ctrlName = directive.controller;

  directive.scope.minChips = "@mdMinChips";

  directive.controller = function($scope, $attrs, $mdConstant, $log, $element, $timeout, $mdUtil) {

    var controller = $controller(ctrlName, {
      $scope: $scope,
      $attrs: $attrs,
      $mdConstant: $mdConstant,
      $log: $log,
      $element: $element,
      $timeout: $timeout,
      $mdUtil: $mdUtil
    }, true);

    console.log("controller", controller);
    return controller;
  }
  console.log('directive', directive)
  return $delegate;
}]);



 我在范围内的附加参数工作正常,但我收到来自库的方法而不是函数的错误。正如我已经以这种方式理解的那样,我重写了原生的Controller原型方法。我做错了什么以及如何扩展Controller?

0 个答案:

没有答案