未捕获的错误: [$injector:modulerr] 由于以下原因,无法实例化模块 myApp: 错误: [$inj
Uncaught error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:unpr] Unknown provider: $routeProvider
我收到此错误:
ncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
Error: [$injector:nomod] Module 'ngRoute' is not available!
You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.4.9/$injector/nomod?p0=ngRoute
这是导致它的代码:
<!Doctype html>
<html data-ng-app="myApp">
<head>
<title>Basic Angular</title>
</head>
<body>
<!-- Placeholder for views -->
<div ng-view="">
</div>
<script src="scripts/angular/angular.js"></script>
<script >
var myApp = angular.module('myApp',[]);
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'views/view1.html',
controller: 'SimpleController'
})
.when('/view2', {
templateUrl: 'views/view2.html',
controller: 'SimpleController'
})
. otherwise({
redirectTo: '/view1'
});
}]);
var controllers = {};
controllers.SimpleController = function( $scope ) {
$scope.cars = [
{brand:'Audi', type:'SUV', name:'Q5'},
{brand:'Audi', type:'Sedan', name:'A7'},
{brand:'Audi', type:'Hatchback', name:'Compact'},
{brand:'BMW', type:'SUV', name:'X5'},
{brand:'BMW', type:'Sedan', name:'X1'},
{brand:'BMW', type:'Hatchback', name:'C3'}
];
$scope.addCar = function () {
$scope.cars.push(
{
brand : $scope.newCar.brand,
type : $scope.newCar.type,
name : $scope.newCar.name
});
};
};
myApp.controller(controllers);
</script>
</body>
我该如何解决?
cdhowie的答案部分正确。下载角度路由库并将其链接到 html 后,您需要在角度模块中注入它的依赖项。像这样的东西..
var myApp = angular.module('myApp',[ngRoute]);
正如错误消息所说,该服务不可用。 您没有包含提供此服务的脚本:
<script src="scripts/angular/angular-route.js"></script>
如果尚未将此脚本下载到开发环境中,则需要将其下载到开发环境中。
相关文章:
- 未捕获错误:由于,[$injector:moduler]未能实例化模块polmgr
- 为什么我在尝试实例化一个空的backbone.js视图时出现类型错误
- 无法实例化Angular js中的模块错误
- 角度错误: [$injector:模块rr] 由于以下原因无法实例化模块角度图表: 错误: [$injector:nom
- 由于以下原因,无法实例化模块 myApp:错误:[$injector:nomod] http://errors.angu
- 未捕获的错误: [$injector:modulerr] 无法实例化模块 toastr
- 未捕获的错误: [$injector:modulerr] 由于以下原因,无法实例化模块 myApp: 错误: [$inj
- 未捕获错误: [$injector:模块rr] 由于以下原因无法实例化模块启动器:错误: [$injector:模块rr
- 未捕获错误:[$injector:moduler]由于以下原因无法实例化模块scheduleApp
- 未捕获的错误:无法为每个类型实例化多个具有相同id的Backbone.RelationalModel
- AngularJS:未捕获错误:$injector:modulerr未能实例化模块
- 实例化模块失败错误:[$injector:unpr]
- 未捕获错误:[$injector:modulerr]实例化模块失败,原因是:
- Angular js错误:[$injector:modulerr]实例化ngroute模块失败,原因是:
- Angular错误[$injector:modulerr]实例化模块myApp失败
- 如何在新的主干中捕获验证错误?实例化期间的模型
- 对象不是函数'尝试用需求实例化木偶应用程序时出现错误
- 错误:[$injector:modulerr]实例化routerApp ui-router模块失败
- 当以编程方式实例化小部件时,Dojo重复ID错误,但不是以声明方式
- 用angular js几乎可以分页任何东西,实例化模块失败错误