我有一个使用ng-include的索引文件来引入标题。这是我的索引文件:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>{{page.title}}</title>
<link rel="stylesheet" href="../dist/libs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../dist/libs/bootstrap/dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="../dist/libs/animate.css/animate.min.css">
<link rel="stylesheet" href="../dist/libs/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../dist/styles/style.min.css">
<script src="../dist/libs/jquery/dist/jquery.min.map"></script>
<script src="../dist/libs/bootstrap/dist/js/bootstrap.min.map"></script>
<script src="../dist/libs/angular/angular.min.js"></script>
<script src="../dist/libs/angular-route/angular-route.min.js"></script>
<script src="../dist/js/controllers.min.js"></script>
<script src="../dist/js/routes.min.js"></script>
<script src="../dist/js/app.min.js"></script>
</head>
<body ng-app="praxis">
<div ng-include="partials/header.html"></div>
<div ng-view></div>
</body>
</html>
我没有收到任何错误,我的控制器正在加载我的ng-view。
这是头文件:
<div id="preloader">
<div id="status"> </div>
</div>
<div id="sb-site">
<div class="boxed">
<header id="header-full-top" class="hidden-xs header-full">
<div class="container">
<div class="header-full-title">
<h1 class="animated fadeInRight">Code<span>.<strong>Praxis</strong></span></h1>
</div>
</div>
</header>
</div>
</div>
路径是否需要基于应用程序运行的位置或索引文件所在的位置?
答案 0 :(得分:7)
你应该在你的情况下提供一个字符串,注意文件路径周围的单引号:
<div ng-include="'partials/header.html'"></div>
来自文档:
角度表达式评估为URL。如果源是字符串常量,请确保将其包装在单引号中,例如SRC =&#34;&#39; myPartialTemplate.html&#39;&#34;
答案 1 :(得分:0)
ng-include
将角度表达式计算为URL。如果源是字符串常量,请确保将其包装在单引号中,例如src="'myPartialTemplate.html'"
所以你的代码应该是:
<div ng-include="'partials/header.html'"></div>
see详细信息
答案 2 :(得分:-1)
我认为你必须这样写:
<div ng-include src="'partials/header.html'"></div>
使用src属性。