gpt4 book ai didi

javascript - AngularJS 路由无法注入(inject)模块

转载 作者:行者123 更新时间:2023-11-28 18:14:38 25 4
gpt4 key购买 nike

我尝试了一些示例,并尝试将模板路由并注入(inject)到 HTML 中。无法将模块注入(inject) HTML div 中。

index.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="MyApp">
<head>
<script src="Script/angular.min.js"></script>
<script src="Script/angualr-route.min.js"></script>
<script src="Script/Script.js"></script>
</head>
<body>
<table style="font-family:Arial">
<tr>
<td class="leftMenu">

<a href="#/aboutme">About Me</a><br /><br />
<a href="#/contact">Contact</a><br /><br />
</td>
<td class="mainContent">
<div ng-view></div>
</td>
</tr>
</table>
</body>
</html>

脚本.js:

var app = angular.module("MyApp", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when("/aboutme", {
templateUrl: "Templates/aboutme.html",
controller: "aboutmeController"
})
.when("/contact", {
templateUrl: "Templates/contact.html",
controller: "contactController"
})
})

我不确定缺少什么。有人可以指出问题或提供建议吗?

我在开发者工具的控制台选项卡中发现了此错误:

Error: $injector:modulerr
Module Error
http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=MyApp&p1=Error: [$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=%24routeprovider
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:6:416
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:41:121
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:39:92)
at Object.e [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:39:362)
at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:38:64)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:38:188
at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:7:333)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:37:488)
at eb (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:41:249)
at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:19:463

最佳答案

您还应该在 Script.js 中为您的应用程序编写一个 Controller 。因此,根据您的情况,请尝试以下操作:

    app.controller('MyApp', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});

关于javascript - AngularJS 路由无法注入(inject)模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40962021/

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