我刚刚学习 angular.js 这是我的第一个“hello world”脚本。我正在尝试使用 ng-include 包含本地文件/templates/nav.html 中的导航栏。我正在遵循教程,但无法弄清楚为什么它不起作用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello World</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body ng-app="app">
<header ng-include src="'templates/nav.html'">
</header>
<div ui-view></div>
<section>
</section>
<footer>
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/app.js"></script>
</body>
这是我的 js/app.js 文件:
angular
.module('app', [
'ui.router'
]);
templates/nav.html 只是默认的引导导航栏。我做错了什么?
最佳答案
您需要将 js/app.js 文件作为脚本包含进来 - 目前还没有实例化 Angular 应用程序。
将此添加为要包含的最后一个脚本:
<script src="js/app.js"></script>
关于javascript - Angular ng-include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634018/