我想加载一个内联视图模板。
我将模板包装在 type 的脚本标记中text/ng-template
,并将 id 设置为temp1.html
. 这就是我的模块配置的样子
learningApp.config(function ($routeProvider) {
$routeProvider
.when("/first",{ controller: "SimpleController", templateUrl: "temp1.html"})
.when("/second", {controller: "SimpleController", templateUrl: "temp2.html"})
.otherwise({redirectTo : "/first"});
});
它在我的控制台窗口中告诉我GET http://localhost:41685/temp1.html 404 (Not Found)
,这意味着它正在寻找该名称的文件。
我的问题是:如何配置我的路线以使用内联模板?
更新:这是我的服务器渲染 DOM 的样子
<!DOCTYPE html>
<html>
<head>
<script src="/Scripts/angular.js"></script>
<link href="/Content/bootstrap.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<h2>Getting Started with Angular</h2>
<div class="row">
<div class="panel" ng-app="LearningApp">
<div ng-view></div>
</div>
</div>
<script type="text/ng-template" id="temp1.html">
<div class="view">
<h2>First View</h2>
<p>
Search:<input type="text" ng-model="filterText" />
</p>
<ul class="nav nav-pills">
<li ng-repeat="cust in customers | orderBy:'name' | filter: filterText "><a href="#">{{cust.name}} - {{cust.school}}</a></li>
</ul>
</div>
</script>
<script type="text/ng-template" id="temp2.html">
<div class="view">
<h2>Second View</h2>
<p>
Search:<input type="text" ng-model="filterText" />
</p>
<ul class="nav nav-pills">
<li ng-repeat="cust in customers | orderBy:'name' | filter: filterText "><a href= "#">{{cust.name}} - {{cust.school}}</a></li>
</ul>
</div>
</script>
</div>
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/app/LearningApp.js"></script>
</body>
</html>