为什么未定义$ injector

时间:2018-08-12 08:23:33

标签: angularjs

出现以下错误:

Uncaught ReferenceError: $injector is not defined

控制台中出现错误。

这是我将其编码到控制器中的方式:

(function () {
'use strict';

    angular.module('DIApp', [])
    .controller('DIController', DIController);

    function DIController ($scope, $filter, $injector) {
        $scope.name = "Yaakov";

        $scope.upper = function() {
            var upCase = $filter('uppercase');
            $scope.name = upCase($scope.name);
        };
    }

    console.log($injector.annotate(DIController));

    function AnnotateMe(name, job, blah) {
        return "Blah!";
    }


})();

这是HTML:

    <body>
      <h1>Dependency Injection in Javascript
                (and Angularjs</h1>
      <div ng-controller="DIController">
          <input type="text" ng-model="name" ng-blur="upper()">
      </div>
  </body>

1 个答案:

答案 0 :(得分:-1)

如上所述声明$ injector

var $injector = angular.injector();

然后

console.log($injector.annotate(DIController));