捕获错误:[$ injector:unpr]当注入$ scope时 [英] Getting Uncaught Error: [$injector:unpr] when $scope injected
本文介绍了捕获错误:[$ injector:unpr]当注入$ scope时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试在下面的代码中添加 $ scope
时,出现错误
When I try to add $scope
in the below give code I am getting error
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
推荐答案
您不能将 $ scope
注入运行组件.或者,您必须使用 $ rootScope
.因为顶级范围是rootScope,所有子范围都是从其继承的
you can't inject $scope
to the run component. alternatively, you have to use the $rootScope
.Because top-level scope is rootScope and all child scope is inherit from it
angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers'])
.run(['$window', '$location', '$rootScope', function ($window, $location, $rootScope) {
}]);
这篇关于捕获错误:[$ injector:unpr]当注入$ scope时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文