html - 当匹配 ng-if 时停止 ng-repeat

标签 html angularjs

我有一个这样的对象:

person:
    phone:
      phone1:
        number:"xxx-xxx-xxxx"
        checkedSms:true/false
      phone2:
        number:"xxx-xxx-xxxx"
        checkedSms:true/false
    smsNumber:""

我有一个链接<a>我只想在特定条件下显示它:任一手机 checkedSms为 true( person.phone.phone[i].checkedSms = true ) 或 smsNumber.length > 0 .

我可以这样做第二部分:

    <a ng-click="..." ng-if="person.smsNumber.length > 0"
        <div>
             ...
        </div>
    </a>

但我不知道如何添加第一部分,并将其与上面的第二部分结合起来。尝试过ng-repeat重复检查该人的手机,但多次匹配结果为多个 <a>展示。该链接应该只显示一次,只要一个条件匹配,它就应该停止进一步检查。

希望有人能帮助我。多谢。

最佳答案

我就是这样做的。

在 HTML 中:

<a ng-if="checkForSms()" ng-click="...">

在 Controller 中:

$scope.checkForSms = function() {
// code that returns true if the conditions are met
}

此外,我将开始使用“controllerAs”语法来为 Angular 2.0 做准备。 https://www.airpair.com/angularjs/posts/preparing-for-the-future-of-angularjs#3-2-remove-dependencies-on-scope

关于html - 当匹配 ng-if 时停止 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34213256/

相关文章:

html - 如何使用 CSS 为选定的列表项赋予不同的颜色?

c# - body 最大高度;纵横比;飞涨

html - 哪种CSS样式处理按钮上的点击事件?除了悬停

html - css 获取 float div 以垂直堆叠

css - 使用 ion-list 使用 ionicframwork 的主详细信息 View

javascript - angularjs - 指令模板未以正确的方式编译

css - 缩小时 Div 会移动。当我有奇数时如何使用百分比?

javascript - 仅当在 ui-grid Angular 中至少选择一行时才启用按钮

javascript - 如何在 Jasmine 测试中释放 AudioContext

javascript - 在 Jasmine JS 测试中未触发 AngularJS Promise 回调