相关疑难解决方法(0)

错误:[$ injector:unpr]未知提供者:$ routeProvider

我正在尝试启动并运行AngularJS 1.2 RC2应用程序.目前,我一直在使用Angular Seed项目尝试启动并运行我的应用程序.不幸的是,Angular Seed项目使用v1.0.7.从Angular Seed项目中,我已将依赖项更新为以下内容:

$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']);
});
Run Code Online (Sandbox Code Playgroud)

在app.js中,我有以下内容:

'use strict';

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

当我运行此应用程序时,我收到以下错误:

Error: [$injector:unpr] Unknown provider: $routeProvider
Run Code Online (Sandbox Code Playgroud)

我已经阅读了一些其他的回答,例如1)注入'ngroute'或2)你需要在路线中定义控制器.我的问题是,我不明白如何注入ngroute.另外,我真的需要在路线中定义控制器吗?这种方法似乎不具备可扩展性.我的应用程序可能有一千个视图.在我看来,似乎必须有方法来定义路由而不必加载所有控制器.

angularjs

66
推荐指数
2
解决办法
13万
查看次数

AngularJS错误:$ injector:unpr未知提供程序

我正在尝试通过遵循工厂方法文档中的示例来构建自己的服务.我认为我做错了但是因为我继续得到未知的提供程序错误.这是我的应用程序代码,包括声明,配置和工厂定义.

编辑我现在已经添加了所有文件来帮助排除故障

编辑错误的完整详细信息低于getSettings的问题,因为它正在寻找getSettingsProvider而无法找到它

Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr?    p0=getSettingsProvider%20%3C-%20getSettings
    at Error (native)
    at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:6:450
    at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:35:431
    at Object.c [as get] (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:13)
    at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:35:499
    at c (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:13)
    at d (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:230)
    at Object.instantiate (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:394)
    at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:66:112
    at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:53:14 angular.js:9778
(anonymous function) angular.js:9778
(anonymous function) angular.js:7216
h.$apply angular.js:12512
(anonymous function) angular.js:1382
d angular.js:3869
$b.c angular.js:1380
$b angular.js:1394
Wc angular.js:1307
(anonymous function) angular.js:21459
a angular.js:2509
(anonymous function) angular.js:2780
q angular.js:330
c
Run Code Online (Sandbox Code Playgroud)



这些是我目前在我的应用程序中的所有文件

app.JS

//Initialize angular module include route dependencies

var app = angular.module("selfservice", ['ngRoute']);

app.config(function ($routeProvider) …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-service

55
推荐指数
4
解决办法
20万
查看次数

标签 统计

angularjs ×2

angularjs-service ×1

javascript ×1