更新:Angular.js 似乎不喜欢
中的
- 。因此,正如有帮助的评论者所说,用
可以解决问题。
抱歉,如果这可能是 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/ ):
这是标题,2007/2011
这是地方(城市,国家)
描述测试
标题测试:4 - 项目测试 3
现在有人能告诉我为什么“{{item.points.length}} - {{item.points[2].text}}”位工作正常但“{{item.points[2 ].text}}"而 UL 中的 ng-repeat 不是吗?
非常感谢
最佳答案
您使用的是 <ol>
标签内 <p>
标签。根据Html documentation
列表元素(特别是 ol 和 ul 元素)不能是 p 元素的子元素。
所以改变<p ng-repeat="">
至 <div ng-repeat="">
或 <span ng-repeat="">
在堆栈溢出中看到这个问题 Should ol/ul be inside <p>
or outside?
关于javascript - UL 内的 ng-repeat(位于 P 内)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975557/