$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