我正在使用Node.js + Express编写一个Web应用程序(使用HoganJs作为模板引擎)和前端的AngularJS。我遇到了ng-repeat渲染正确数量的元素的问题,但是没有任何内容。我将ng-repeat打破了一个较小的例子,它仍然没有渲染。
编辑:Plunkr中有一个拼写错误,所以我将其删除了。这是我的应用程序中更多扩展的摘录。
以下是我的观点的一部分:index.hjs
<div class="search-results" ng-controller="results">
<ul class="tracks">
<li class="track" ng-repeat="track in tracks">
<ul class="meta">
<li>
<div class="name">
<span class="value">{{track.name}}</span>
</div>
</li>
<li>
<div class="album">Album:
<span class="value">{{track.album}}</span>
</div>
</li>
<li>
<div class="artist">Artist:
<span class="value">{{track.artist}}</span>
</div>
</li>
<li>
<div class="length">Length:
<span class="value">{{track.length}}</span>
</div>
</li>
</ul>
</li>
</ul>
</div>
结果控制器:js/controllers/results.js
var results = function($scope, socket) {
$scope.tracks = [
{"uri":"spotify:track:1jdNcAD8Ir58RlsdGjJJdx","name":"Ho Hey","artist":"The Lumineers","album":"The Lumineers"},
{"uri":"spotify:track:3uuGbRzMsDI5RiKWKOjqWL","name":"Hey Porsche","artist":"Nelly","album":"Hey Porsche"},
{"uri":"spotify:track:5BSndweF91KDqyxANsZcQH","name":"Ho Hey","artist":"The Lumineers","album":"The Lumineers"},
{"uri":"spotify:track:2UNc0duOP4cS7gqYFFkwxT","name":"Hey Girl","artist":"Billy Currington","album":"Hey Girl"},
{"uri":"spotify:track:6fgbQt13JlpN59PytgTMsA","name":"Snow [Hey Oh]","artist":"Red Hot Chili Peppers","album":"Snow [Hey Oh]"}
];
socket.on("results", function(tracks) {
$scope.tracks = tracks;
console.dir(JSON.stringify($scope.tracks));
});
$scope.add = function(uri) {
socket.emit("add", uri);
};
};
最后我的模块:app.js
var app = angular.module("app", []);
var factories = {
socket: socket
};
app.factory(factories);
var controllers = {
actions: actions,
search: search,
results: results,
queue: queue
};
app.controller(controllers);
出于测试目的,当应用程序运行时,轨道会被硬编码5 li
被渲染但是内部没有内容模板化。
答案 0 :(得分:1)
答案 1 :(得分:1)
我刚刚意识到这里发生了什么。当页面在服务器上呈现时,Hogan.js会覆盖angular的模板。
答案 2 :(得分:0)
只需删除添加到脚本中的额外括号(第19行)。请看这里的脚本。 http://plnkr.co/edit/sy2m0RuXRudGvjnmfC3Y?p=preview