$ injector:strictdi - 关注John Pappas风格指南

时间:2016-06-19 01:05:10

标签: angularjs

现在跟随John Pappas风格指南一段时间。我在使用建议的方法创建指令时遇到了问题。我得到$ injector:strictdi错误,但不是100%确定为什么?如果有人可以看看下面的代码,并指出哪些是错的,那就太好了!

'use strict';

(function() {
angular
  .module('app.components')
  .directive('myAccount', myAccount);

function myAccount() {
  var directive = {
    templateUrl: 'client/app/components/my_account/my_account.html',
    restrict: 'EA',
    controller: MyAccountController,
    controllerAs: 'vm',
    bindToController: true
  };
  return directive;

  MyAccountController.$inject = ['$scope'];

  function MyAccountController($scope) {
    var vm = this;
    vm.showBtn = false;
    vm.showIt = showIt;
    $scope.$apply();
  }

  function showIt() {
    console.log('Show it');
  }
}

})();

1 个答案:

答案 0 :(得分:0)

仅供参考This github issue shows the same thing

您的问题是您在注射发生之前返回指令,因此,当您缩小注射代码时,注射代码将无法访问。你应该在返回指令之前注入。

相关问题