Error: [$injector:itkn] Incorrect injection token! Expected service name as string, got undefined

Error: [$injector:itkn] Incorrect injection token! Expected service name as string, got undefined

这是我 的问题的延续。我得到

错误:[$injector:itkn] 注入令牌不正确!预期服务名称为字符串,未定义。当我在控制器构造函数中使用 [] 时,我得到了

错误:[$injector:unpr] 未知提供者:$scopeProvider <- $scope <- HomeCtrl

 $controller("HomeCtrl",[{
              $scope: scope
            }]);

感谢您的帮助。

/// <reference path="../../_references.js" />

'use strict';

describe('Controllers: HomeCtrl', function() {
      var $controller, scope;
      beforeEach(module('myApp.controllers'));
      beforeEach(inject(function($rootScope, $controller) {
        scope = $rootScope.$new();
        $controller("HomeCtrl", {
          $scope: scope
        });
      }));

      it('should has title equals to My App', function() {
        expect(scope.title).toEqual('My App');
      });
}

HomeController.js是这样的:

'use strict';

angular.module('myApp.controllers')
   // Path: /
  .controller('HomeCtrl', ['$scope', '$location', '$window', /*'version'*/,
    function ($scope, $location, $window, version)
    {
      $scope.$root.title = 'AngularJS SPA | Home';
      //$scope.appVersion = version;
      $scope.title = 'My App';
    }]);

.controller('HomeCtrl', ['$scope', '$location', '$window', /*'version',*/
    function ($scope, $location, $window)

您必须删除评论后的逗号 - 就像这样,您后面有 2 个逗号解析为未定义的值。您还必须从函数中删除 version,否则参数与签名不匹配。

实际问题是我在控制器中多了一个 , 。当我改变它时,它起作用了。 , 函数 ($scope, $timeout ....