更新:似乎Angular.js不喜欢< ul>在< p>内因此,正如有用的评论者所说,替换< p>使用< div>解决了这个问题。
很抱歉,如果这可能是Angular.js上的新手问题,但我似乎无法在此代码中找到错误。请考虑以下HTML:
<div ng-app ng-controller="BlocksCtrl">
<div ng-repeat="block in blocks">
<div id="{{block.id}}" class="{{block.classes}}">
<div>
<h1>{{block.title}}, {{block.dates}}
<br/>
<small>
<a href="{{block.place.link}}" target="_blank">
{{block.place.title}}</a>
({{block.place.city_country}})
</small>
</h1>
</div>
<div>
<div>
<p><i class="{{block.icon_classes}}"></i></p>
</div>
<div>
<p>
{{block.description.text}}
</p>
<p ng-repeat="item in block.description.items">
<b>{{item.title}}</b>: {{item.points.length}} - {{item.points[2].text}}
<ul class="fa-ul">
<li>
<i class="fa-li fa fa-check"></i>{{item.points[2].text}}
</li>
<li ng-repeat="point in item.points">
<i class="fa-li fa fa-check"></i>{{point.text}}
</li>
</ul>
</p>
</div>
</div>
</div>
</div>
</div>
这是Javascript位:
function BlocksCtrl($scope) {
$scope.blocks = [
{
id: 'my-id',
classes: 'class1 class2',
title: 'This is the title',
dates: '2007 / 2011',
place: {
link: 'http://www.example.com/',
title: 'This is the place',
city_country: 'City, Country'
},
icon_classes: 'fa fa-terminal fa-5x',
description: {
text: 'description test',
items: [
{
title: 'Title test',
points: [
{text: 'item test 1'},
{text: 'item test 2'},
{text: 'item test 3'},
{text: 'item test 4'}
]
}
]
}
}
];
}
这将显示以下输出(您可以在JSFiddle上查看一个工作示例 http://jsfiddle.net/uskL6/):
描述测试
标题测试:4 - 项目测试3
现在有人可以告诉我“{{item.points.length}} - {{item.points [2] .text}}”位是如何工作的,但是“{{item.points [2] ] .text}}“和UL内部的ng-repeat没有?
非常感谢
答案 0 :(得分:6)
您在<ol>
标记内使用了<p>
标记。根据{{3}}
列表元素(特别是ol和ul元素)不能是p元素的子元素。
所以将<p ng-repeat="">
更改为<div ng-repeat="">
或<span ng-repeat="">
在堆栈溢出 Html documentation
中查看此问题答案 1 :(得分:1)
起初我觉得这很简单......
然后它让我疯了......
解决方案:将<p ng-repeat="...">
更改为<div ng-repeat="...">
。然后它工作;为什么,我不知道...