gpt4 book ai didi

javascript - Angular ngView 不显示页面

转载 作者:行者123 更新时间:2023-12-03 08:18:05 28 4
gpt4 key购买 nike

当我点击链接加载 ngView 页面时,html 文件不会显示。

我没有通过本地主机运行应用程序,我怀疑这可能是问题所在。我刚刚用 Chrome 打开了 index.html,所以也许 ngRoute 缺少一些依赖项?


路由器应用程序/
---index.html
---app.js
---pages/
-------home.html
--------about.html
-------contact.html

无论如何,这是我的 app.js

// app.js

// create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function($routeProvider){
$routeProvider

//route for home page
.when('/', {
templateURL: 'pages/home.html',
controller: 'mainController'
})

//route for home page
.when('/about', {
templateURL: 'pages/about.html',
controller: 'aboutController'
})

//route for home page
.when('/contact', {
templateURL: 'pages/contact.html',
controller: 'contactController'
})

//default route
.otherwise({
redirectTo: '/'
});
});

// create the controller and inject Angular's $scope
scotchApp.controller('mainController', function($scope) {

// create a message to display in our view
$scope.message = 'Everyone come and see how good I look!';
});

scotchApp.controller('aboutController', function($scope){
$scope.message = 'Look! I am on the About page!';
});

scotchApp.controller('contactController', function($scope){
$scope.message = 'Shoutout! I am on the Contact page!';
});

这里是index.html

<!-- index.html -->
<!DOCTYPE html>
<html ng-app='scotchApp'>
<head>

<BASE href="/Users/Khan/Desktop/router-app/">
<!-- SCROLLS -->
<!-- load bootstrap and fontawesome via CDN -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />

<!-- SPELLS -->
<!-- load angular and angular route via CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="script.js"></script>

<meta charset='utf-8'>
<base href='/'>
</head>
<body>

<!-- HEADER AND NAVBAR -->
<header>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">Angular Routing Example</a>
</div>

<ul class="nav navbar-nav navbar-right">
<li><a href="#"><i class="fa fa-home"></i> Home</a></li>
<li><a href="#about"><i class="fa fa-shield"></i> About</a></li>
<li><a href="#contact"><i class="fa fa-comment"></i> Contact</a></li>
</ul>
</div>
</nav>
</header>

<!-- angular templating -->
<!-- this is where content will be injected -->
<div ng-view></div>

</body>
</html>

我很好奇到底发生了什么,如果有人知道的话。感谢您的帮助! :)

最佳答案

从模板网址中删除前导斜杠,

/Pages/about.html

应该变成

页面/about.html

关于javascript - Angular ngView 不显示页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33849261/

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