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

标签 javascript angularjs

我在系统上运行 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/

相关文章:

javascript - Framer.js 工作室 PSD

javascript - 从 CRM 2011 表单的表单标题中检索字段

Javascript - Div/Image 从顶部向下滑动

javascript - AngularJS HTTP 拦截器

javascript - 使用 JS 查找素数序列

javascript - 使用 angularjs 指令的引号

javascript - 如何在 javascript 中创建通用方法来根据输入构建 json 请求?

javascript - 如何更新 angular.forEach() 中的当前值?

angularjs - chai-as-promised 测试不适用于 $q promise

javascript - 如何使用 AngularJS 将多个参数发送到 JAVA API