【问题标题】:Don't repeat element in ng-repeat scope不要在 ng-repeat 范围内重复元素
【发布时间】:2016-04-15 17:12:08
【问题描述】:

是否有可能以某种方式定义角度,我不想在ng-repeat 范围内重复一些 html 标签。例如我想创建一个这样的选项卡过滤器:

 <div class="searchandfilter" ng-app="phonecatApp">
    <span ng-controller="PhoneListCtrl"> 
        <span ng-repeat="phone in phones" class="tab-controller">
            <ul>
                <li class="tab" >{{phone.name}}</li>
            </ul>
            <span class="tab-content dont-repeat">
                <span>
                    <input type="checkbox">{{phone.brand}}</input>
                </span>
            </span>
        </span>
    </span>
</div>

我不想用 dont-repeat 类重复 span,但我需要在里面重复 spaninput

JSFiddle

【问题讨论】:

  • 我不明白你想在这里实现什么。你能给我们举个例子吗,有 3 或 4 部手机,你希望生成的 HTML 看起来像什么?你想达到什么目标?

标签: angularjs angularjs-ng-repeat ng-repeat angularjs-controller


【解决方案1】:

只需在ng-if 中使用$first 即可,例如ng-if="$first"

标记

<span  ng-if="$first" class="tab-content dont-repeat">
    <span>
       <input type="checkbox">{{phone.brand}}</input>
    </span>
</span>

JSFiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-12
    • 2013-04-05
    • 2014-07-11
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多