错误:[$喷油器:unpr]未知提供商:$ routeProvider [英] Error: [$injector:unpr] Unknown provider: $routeProvider

查看:120
本文介绍了错误:[$喷油器:unpr]未知提供商:$ routeProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到一个AngularJS 1.2 RC2应用程序启动和运行。目前,我已经用角种子工程,试图让我的应用程序启动和运行了。不幸的是,角种子项目使用v1.0.7。从角种子项目,我已经更新了依赖关系如下所示:

I am trying to get an AngularJS 1.2 RC2 app up and running. Currently, I've been using the Angular Seed project to try and get my app up and running. Unfortunately, the Angular Seed project uses v1.0.7. From the Angular Seed project, I've updated the dependencies to be the following:

$script([
  'res/js/angular-1.2.0-rc.2.js',
  'res/js/angular-route-1.2.0-rc.2.js',
  'res/js/app.js?v=2',
], function() {
  // when all is done, execute bootstrap angular application
  angular.bootstrap(document, ['myApp']);
});

在app.js,我有以下几点:

In app.js, I have the following:

'use strict';

angular.module('myApp', []).
    config(['$routeProvider', function($routeProvider) {
        $routeProvider.otherwise({redirectTo: '/home'});
    }]);

当我运行这个程序,我得到以下错误:

When I run this app, I get the following error:

Error: [$injector:unpr] Unknown provider: $routeProvider

我读过一些说这样的话1其他响应)注入ngroute'或2)您需要定义在路由控制器。我的问题是,我不明白如何注入ngroute。此外,我真的需要来定义路由控制器?这种做法似乎并不可扩展性。我的应用程序可能有一千个看法。在我看来,这似乎只是必须有方法来定义的路由,而无需加载所有的控制器。

I've read some of the other responses that say things like 1) Inject 'ngroute' or 2) You need to define the controller in the route. My problem is, I don't understand how to inject ngroute. In addition, do I really need to define the controller in the route? That approach doesn't seem scalable. My app may have a thousand views. In my opinion, it just seems like there has to be way to define routes without having to load all of the controllers.

推荐答案

在角1.4 +,除了添加依赖

In angular 1.4 +, in addition to adding the dependency

angular.module('myApp', ['ngRoute'])

,我们还需要引用单独的角route.js文件

,we also need to reference the separate angular-route.js file

<script src="angular.js">
<script src="angular-route.js">

请参见 https://docs.angularjs.org/api/ngRoute

这篇关于错误:[$喷油器:unpr]未知提供商:$ routeProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆