UL内部的ng-repeat(在P内部)不起作用

时间:2022-12-02 17:41:59

UPDATE: It seems Angular.js doesn't like the <ul> inside a <p>. So, as helpful commenters said, replacing the <p> with a <div> solves the problem.

更新:似乎Angular.js不喜欢

中的

    。因此,正如有用的评论者所说,用
    替换

    可以解决问题。

Sorry if this may be a newbie question on Angular.js but I just can't seem to find the error in this code. Consider the following HTML:

很抱歉,如果这可能是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>

This is the Javascript bit:

这是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'}
            ]
          }
        ]
      }
    }
  ];
}

This will display the following output (you can check a working example on JSFiddle http://jsfiddle.net/uskL6/):

这将显示以下输出(您可以在JSFiddle http://jsfiddle.net/uskL6/上查看一个工作示例):


This is the title, 2007 / 2011

This is the place (City, Country)

description test

描述测试

Title test: 4 - item test 3

标题测试:4项测试3


Now can someone tell me how is it that the "{{item.points.length}} - {{item.points[2].text}}" bit works fine but the "{{item.points[2].text}}" and the ng-repeat inside the UL don't?

现在有人可以告诉我,“{{item.points.length}} - {{item.points [2] .text}}”位如何工作正常,但是“{{item.points [2] .text “和UL内部的ng-repeat没有?

Thanks a bunch

谢谢你们

2 个解决方案

#1


6  

You were using <ol> tag inside <p> tag. According to Html documentation List elements (in particular, ol and ul elements) cannot be children of p elements.

您在

标签内使用了

    标签。根据Html文档List元素(特别是ol和ul元素)不能是p元素的子元素。

So change <p ng-repeat=""> to <div ng-repeat=""> or <span ng-repeat="">

所以将

更改为

See this question in stack overflow Should ol/ul be inside <p> or outside?

在堆栈溢出中看到这个问题应该ol / ul在

内还是在外面?

#2


1  

At first I thought it was simple...

起初我觉得这很简单......

Then it drove me crazy...

然后它让我发疯了......

The solution: Change the <p ng-repeat="..."> to <div ng-repeat="...">. Then it works; why, I do not know...

解决方案:将

更改为

。然后它工作;为什么,我不知道......

#1


6  

You were using <ol> tag inside <p> tag. According to Html documentation List elements (in particular, ol and ul elements) cannot be children of p elements.

您在

标签内使用了

    标签。根据Html文档List元素(特别是ol和ul元素)不能是p元素的子元素。

So change <p ng-repeat=""> to <div ng-repeat=""> or <span ng-repeat="">

所以将

更改为

See this question in stack overflow Should ol/ul be inside <p> or outside?

在堆栈溢出中看到这个问题应该ol / ul在

内还是在外面?

#2


1  

At first I thought it was simple...

起初我觉得这很简单......

Then it drove me crazy...

然后它让我发疯了......

The solution: Change the <p ng-repeat="..."> to <div ng-repeat="...">. Then it works; why, I do not know...

解决方案:将

更改为

。然后它工作;为什么,我不知道......