1

不确定到底发生了什么,但看起来我的表达式没有得到评估或扩展。

        <div ng-repeat-start="q in questions">
            <h3>{{q.text}}</h3>

                <p ng-if="q.type == 'checkbox'">
                    <p ng-repeat-start="a in q.answers">1 {{q.type}}
                        <input type={{q.type}}>{{a.text}}</input><br/>
                    </p>
                    <p ng-repeat-end></p>
                </p>

                <p ng-if="q.type == 'radio'">
                    <p ng-repeat-start="a in q.answers">2 {{q.type}}
                        <input type={{q.type}}>{{a.text}}</input><br/>
                    </p>
                    <p ng-repeat-end></p>
                </p>
        </div>
        <p ng-repeat-end></p>

输出显示代码正在执行每个 if,就好像它们都是真的一样。这会产生重复的复选框/单选按钮。

    1 checkbox  Voice calling.
    1 checkbox  Text messaging.
    1 checkbox  Data access 
    2 checkbox  Voice calling.
    2 checkbox  Text messaging.
    2 checkbox  Data access 

它应该如下所示:

    1 checkbox  Voice calling.
    1 checkbox  Text messaging.
    1 checkbox  Data access
    2 radio  new question 1.
    2 radio  new question 2.
    2 radio  new question 3.
4

1 回答 1

2

您的问题是nested p标记更多详细信息

<p>this
  <p>will not work</p>
</p>

P 元素代表一个段落。它不能包含块级元素(包括 P 本身)。

在这种情况下,ng-if指令将无法正确评估。因此,如果您使用divorspan代替pthen 它应该可以工作

    <div ng-repeat-start="q in questions">
        <h3>{{q.text}}</h3>

            <span ng-if="q.type == 'checkbox'">
                <p ng-repeat-start="a in q.answers">1 {{q.type}}
                    <input type={{q.type}}>{{a.text}}<br/>
                </p>
                <p ng-repeat-end></p>
            </span>

            <span ng-if="q.type == 'radio'">
                <p ng-repeat-start="a in q.answers">2 {{q.type}}
                    <input type={{q.type}}>{{a.text}}<br/>
                </p>
                <p ng-repeat-end></p>
            </span>

    </div>
    <p ng-repeat-end></p>

演示

于 2014-04-20T17:42:22.070 回答