[英]AngularJS, ng-repeat with ng-include not rendering
嗨,我開始學習角度,當我使用ng-repeat和ng-include的組合時,我遇到了問題。 無論我做什么,我都無法獲得要渲染的模板。 我有一個簡單的控制器,它創建一個工作區列表,每個工作區都有一個TemplateUrl屬性。
我知道這個值是正確的,因為如果我只是渲染原始文本{{workspace.TemplateUrl}}然后將其直接放入ng-include中就沒問題了。 當它來自控制器時它似乎永遠不會起作用。 我已經嘗試將模板路徑放在這樣的引號中,但它沒有任何區別。
$scope.Workspaces.push(new Workspace("'/app/templates/Template1.html'", "Workspace 1"));
當我運行它時,我看不到拉模板的請求。 任何人都可以幫助這個,因為它讓我有點瘋狂。
<!DOCTYPE html>
<html ng-app>
<head>
<title>Workspaces</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<script src="app/libraries/jquery.js"></script>
<script src="app/libraries/bootstrap.min.js"></script>
<script src="app/libraries/angular.js"></script>
<script src="app/app.js"></script>
</head>
<body ng-controller="HostController">
<div>
<ul class="unstyled">
<li ng-repeat="workspace in Workspaces">
<p>{{workspace.TemplateUrl}}</p>
<hr />
<div ng-include="{{workspace.TemplateUrl}}"></div>
</li>
</ul>
</div>
</body>
</html>
控制器代碼
var Workspace = (function () {
function Workspace(templateUrl, name) {
this.TemplateUrl = templateUrl;
this.Name = name;
}
return Workspace;
})();
function HostController($scope) {
$scope.Workspaces = new Array();
$scope.Workspaces.push(new Workspace("/app/templates/Template1.html", "Workspace 1"));
$scope.Workspaces.push(new Workspace("/app/templates/Template2.html", "Workspace 2"));
$scope.Workspaces.push(new Workspace("/app/templates/Template1.html", "Workspace 3"));
$scope.Workspaces.push(new Workspace("/app/templates/Template2.html", "Workspace 4"));
$scope.Workspaces.push(new Workspace("/app/templates/Template1.html", "Workspace 5"));
}
我引用你的代碼
<div ng-include="{{workspace.TemplateUrl}}"></div>
應該
<div ng-include="workspace.TemplateUrl"></div>
因為這是一個ng聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.