不能得到$ rootScope [英] Cannot get to $rootScope
本文介绍了不能得到$ rootScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下列文件作品(这个意义上讲,它不抛出任何错误)
The following file "works" (the sense that it does not throw any errors):
<!doctype html>
<html ng-app="modx">
<script src="http://code.angularjs.org/angular-1.0.0rc7.js"></script>
<script>
angular.module("modx", [], function($routeProvider) {
});
</script>
</html>
但这种
<!doctype html>
<html ng-app="modx">
<script src="http://code.angularjs.org/angular-1.0.0rc7.js"></script>
<script>
angular.module("modx", [], function($routeProvider, $rootScope) {
});
</script>
</html>
给出了错误:
错误:未知提供商:从镆铘结果$ rootScope
源文件:<一href=\"http://$c$c.angularjs.org/angular-1.0.0rc7.js\">http://$c$c.angularjs.org/angular-1.0.0rc7.js
行:2491
Error: Unknown provider: $rootScope from modx
Source File: http://code.angularjs.org/angular-1.0.0rc7.js
Line: 2491
跆拳道?
推荐答案
您不能实例期间配置相问 - 你可以要求只对供应商
You can not ask for instance during configuration phase - you can ask only for providers.
var app = angular.module('modx', []);
// configure stuff
app.config(function($routeProvider, $locationProvider) {
// you can inject any provider here
});
// run blocks
app.run(function($rootScope) {
// you can inject any instance here
});
请参阅 http://docs.angularjs.org/guide/module 了解更多信息。
这篇关于不能得到$ rootScope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文