gpt4 book ai didi

javascript - Uncaught Error : Angular even after loading ng-route

转载 作者:行者123 更新时间:2023-11-30 11:53:49 25 4
gpt4 key购买 nike

我遇到了这个可怕的错误:

angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module usersApp 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.

不确定我做错了什么:app.js:

(function () {

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

app.config(['$routeProvider', function ($routeProvider) {

var viewBase = '/';

$routeProvider
.when('/users', {
controller: 'MainController',
templateUrl: viewBase + 'users/users.html',
controllerAs: 'vm'
})
.when('/add', {
controller: 'OrdersController',
templateUrl: viewBase + 'add/orders.html'
})
.otherwise({ redirectTo: '/users' });

}]);


}());

index.html:

<html>
<head>
<title>My Angular App!</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>

<script src="app.js"></script>
</head>
<body ng-app="usersApp" ng-controller="MainCtrl">
<h1>uSers</h1>
<div ng-repeat="user in users" ng-click="getUsers()" style="background: black; padding: 5px; min-width: 25px; color: white;">
{{user}}
</div>
</body>
</html>

感谢您提供的任何帮助!

最佳答案

您忘记包含 angular-route。此外,无需加载 2 个不同版本的 Angular 。将您的主要 html 更改为此:

<html>
<head>
<title>My Angular App!</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.min.js"></script>

<script src="app.js"></script>
</head>
<body ng-app="usersApp" ng-controller="MainCtrl">
<h1>uSers</h1>
<div ng-repeat="user in users" ng-click="getUsers()" style="background: black; padding: 5px; min-width: 25px; color: white;">
{{user}}
</div>
</body>
</html>

关于javascript - Uncaught Error : Angular even after loading ng-route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38676678/

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