无法实例化模块 [$injector:unpr] 未知提供者:$routeProvider [英] Failed to instantiate module [$injector:unpr] Unknown provider: $routeProvider
问题描述
我在从 AngularJS 1.0.7 升级到 1.2.0rc1 时收到此错误.
I received this error upon upgrading from AngularJS 1.0.7 to 1.2.0rc1.
推荐答案
ngRoute 模块不再是核心 angular.js
文件的一部分.如果您继续使用 $routeProvider,那么您现在需要在 HTML 中包含 angular-route.js
:
The ngRoute module is no longer part of the core angular.js
file. If you are continuing to use $routeProvider then you will now need to include angular-route.js
in your HTML:
<script src="angular.js">
<script src="angular-route.js">
您还必须添加 ngRoute
作为您的应用程序的依赖项:
You also have to add ngRoute
as a dependency for your application:
var app = angular.module('MyApp', ['ngRoute', ...]);
如果您打算使用 angular-ui-router
或类似的然后只需从您的模块 .config()
中删除 $routeProvider
依赖项并将其替换为相关的提供程序(例如 $stateProvider
).然后您将使用 ui.router
依赖项:
If instead you are planning on using angular-ui-router
or the like then just remove the $routeProvider
dependency from your module .config()
and substitute it with the relevant provider of choice (e.g. $stateProvider
). You would then use the ui.router
dependency:
var app = angular.module('MyApp', ['ui.router', ...]);
这篇关于无法实例化模块 [$injector:unpr] 未知提供者:$routeProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!