当我尝试在下面的代码中添加$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
答案 0 :(得分:1)
您无法将$scope
注入运行组件。或者,你必须使用$rootScope
。因为顶级范围是rootScope,所有子范围都是从它继承的
angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers'])
.run(['$window', '$location', '$rootScope', function ($window, $location, $rootScope) {
}]);