获取未捕获错误:注入$ scope时[$ injector:unpr]

时间:2017-06-14 10:42:16

标签: angularjs

当我尝试在下面的代码中添加$scope时,我收到错误

angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers'])
  .run(['$window', '$location', '$rootScope', '$scope', function ($window, $location, $rootScope, $scope) {}]);

错误:

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.2.26/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope

1 个答案:

答案 0 :(得分:1)

您无法将$scope注入运行组件。或者,你必须使用$rootScope。因为顶级范围是rootScope,所有子范围都是从它继承的

angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers'])
  .run(['$window', '$location', '$rootScope', function ($window, $location, $rootScope) {

}]);