gpt4 book ai didi

javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:unpr] Unknown provider: $routeProvider

转载 作者:行者123 更新时间:2023-12-02 15:07:19 27 4
gpt4 key购买 nike

我收到此错误:

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 的回答部分正确。下载 Angular 路由库并将其链接到 html 中后,您需要将其依赖项注入(inject) Angular 模块中。像这样的东西..

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

关于javascript - Uncaught Error : [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:unpr] Unknown provider: $routeProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35021637/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com