【问题标题】:Uncaught Error: [$injector:modulerr] in angular js未捕获的错误:角度 js 中的 [$injector:modulerr]
【发布时间】:2016-07-23 11:29:14
【问题描述】:

我收到错误未捕获的错误:[$injector:modulerr]

我已经包含了下面的js文件

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
    <script src="lib/jquery-1.12.1.min.js"></script>

我的js代码是

angular.module('website',['ngRoute','ngResource']).
     config(function($routerProvider){
        $routerProvider.
            when('/about',{template:'templates/about.html'}),
            when('/careers',{template:'templates/careers.html'}),
            when('/signup',{template:'templates/signup.html'}),
            otherwise({redirectTo : '/home', template:'/home.html'})
    })

function mainController($scope){

}

有人请帮帮我,我在哪里失踪。

已编辑: 错误日志是 由于以下原因无法实例化模块网站: 错误:[$injector:unpr]http://errors.angularjs.org/1.4.5/$injector/unpr?p0=%24ro... 在错误(本机) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:6:416https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:40:307 在 d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:38:308) 在 Object.e [作为调用] (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:39:64) 在 d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:279) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:403 在 n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:7:322) 在 g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:37:180) 在 eb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js:40:435

【问题讨论】:

  • 两件事:1)看起来您正在引用每个 Angular 库的不同版本。选择一个版本并将其用于所有参考。 2) 调试时不要使用缩小版。在调试时使用非缩小版本会给您提供更详细的错误消息。
  • 你能把你的整个错误日志贴出来吗??

标签: angularjs angularjs-routing angularjs-templates


【解决方案1】:

Working Plnkr

$routerProvider 更改为$routeProvider。在配置中将, 替换为.。例如:

when('/about',{template:'templates/about.html'}),
when('/careers',{template:'templates/careers.html'})

when('/about',{template:'templates/about.html'})
.when('/careers',{template:'templates/careers.html'})

您的 JavaScript 代码应如下所示:

var website = angular.module('website',['ngRoute','ngResource']);

     website.config(function($routeProvider){
        $routeProvider.
            when('/about',{template:'templates/about.html'})
            .when('/careers',{template:'templates/careers.html'})
            .when('/signup',{template:'templates/signup.html'})
            .otherwise({redirectTo : '/home', template:'/home.html'})
    }) 

website.controller('mainController', function($scope){

});

欲了解更多信息,please have a look at this example

希望能解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2020-07-13
    • 2014-09-28
    相关资源
    最近更新 更多