我想在 ng-repeat 中呈现不同的 html 模板(绑定到模型)。
<div ng-repeat="section in sections | filter:unansweredSections">
// Here i want something like
if section == children
render div#children
else if section == work
render div#work
</div>
<div style="display:none" id="children">
// i want to bind this to sections info
<input ng-model="???.totalChildren" />
</div>
<div style="display:none" id="work">
// i want to bind this to sections info
<input ng-model="???.work1" />
<input ng-model="???.work2" />
</div>
现在在最后两个 div 中,我实际上希望输入绑定到具体部分的参数。
我的模型如下所示:
$scope.sections = [
{"name" : "children","totalChildren" : 0},
{"name" : "work","work1" : "","work2" : ""}
]
我可以把它变成一个对象而不是一个数组
$scope.sections = {
"children" : {"totalChildren" : 0},
"work" : {"work1" : "","work2" : ""}
}
然后轻松绑定到它
<div style="display:none" id="children">
<input ng-model="sections.childern.totalChildren" />
</div>
但是我不能在上面使用过滤器和排序。