gpt4 book ai didi

javascript - 为什么我的 Angular 不能正常工作?

转载 作者:太空宇宙 更新时间:2023-11-04 16:26:43 26 4
gpt4 key购买 nike

我在系统上运行 Angular 时遇到了一些问题。我一直在从 w3 学校的 Angular 演示中学习,这些演示演示了不同的组件。

这是我正在尝试的一个:

http://www.w3schools.com/angular/tryit.asp?filename=try_ng_routing_template

这是我正在使用的代码:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>

<body ng-app="myApp">

<p><a href="#/">Main</a></p>

<a href="#banana">Banana</a>
<a href="#tomato">Tomato</a>

<p>Click on the links to change the content.</p>

<p>The HTML shown in the ng-view directive are written in the template property of the $routeProvider.when method.</p>

<div ng-view></div>

<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
    $routeProvider
    .when("/", {
        template : "<h1>Main</h1><p>Click on the links to change this content</p>"
    })
    .when("/banana", {
        template : "<h1>Banana</h1><p>Bananas contain around 75% water.</p>"
    })
    .when("/tomato", {
        template : "<h1>Tomato</h1><p>Tomatoes contain around 95% water.</p>"
    });
});
</script>

</body>
</html>

它不会在我的系统上的 header 标签之间切换。

编辑:代码在其他地方工作正常,但在我的系统上不行。它在我的 apache 文件夹中。从本地主机运行。 JavaScript、php 和 html 工作正常。我也用过 jQuery。知道为什么 Angular 可能会出现问题吗?

最佳答案

您的文件可能缓存在浏览器中,因此即使保存文件也不会更新浏览器中运行的内容。

清除浏览器缓存。重新启动浏览器。

关于javascript - 为什么我的 Angular 不能正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40158649/

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