$scope.array = [{type: 'event'}, {type: 'alert'}];
我如何可以遍歷這並呈現不同的項目有:$ templateCache每個,基於類型的。我們可以假設存在'event.html'和'alert.html'。
$scope.array = [{type: 'event'}, {type: 'alert'}];
我如何可以遍歷這並呈現不同的項目有:$ templateCache每個,基於類型的。我們可以假設存在'event.html'和'alert.html'。
我認爲你要找的是以下內容。
<div ng-repeat='a in array'>
<div ng-if="a.type =='event'">
// EVENT.html TEMPLATE
</div>
<div ng-if="a.type == 'alert'">
// ALERT.html TEMPLATE
</div>
</div>
你能做些什麼,除了基岡的回答是:
<div ng-repeat='a in array'>
<div ng-include="a.type + '.html'"></div>
</div>
這樣你加載每個值
假設數據來自API,這是否意味着服務器現在指定要使用哪個模板?如果在類型和模板之間存在一些中間映射,可能會更好。 – jsharpe
我聽不懂。你能詳細說明嗎?可能只是在問題中 – binariedMe
尋找一個解決方案,是不太明顯的event.html的error.html或並可以很容易地擴展到許多類型。 – jsharpe