【问题标题】:What is the syntax of angular one time binding for multiple properties in ng-ifng-if中多个属性的角度一次绑定的语法是什么
【发布时间】:2016-02-16 11:01:42
【问题描述】:

我有一个

ng-if="dc.emailNotificationSchedule.progressInterval === dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN"

我想要做的是对ng-if 中的两个变量进行一次绑定。但是当我尝试使用

ng-if="(::dc.emailNotificationSchedule.progressInterval) === (::dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN)"

angular 抛出以下错误:

错误:[$parse:syntax] 语法错误:令牌 ':' 不是主要的 表达式第 2 列的表达式 [(::dc.emailNotificationSchedule.progressInterval) === (::dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN)] 开始于
[::dc.emailNotificationSchedule.progressInterval) ===
(::dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN)]。

什么是正确的方法?

【问题讨论】:

    标签: angularjs angular-ng-if one-time-binding


    【解决方案1】:

    试试这个方法:

    ng-if="::(dc.emailNotificationSchedule.progressInterval === dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN)"
    

    【讨论】:

    • 这样它不会按预期工作,因为当任何一个属性变得稳定时,表达式本身就会变得稳定(在这种情况下为 false,因为那时第二个参数将为 null)并且整个表达式的观察者将被删除。因此,当第二个属性变得稳定时,它的值不会对整个表达式结果产生任何影响。
    • 可以加dc.emailNotificationSchedule.progressInterval === undefined ? undefined : dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN === undefined ? undefined : ...
    • 是的,但是表达式变得太复杂了,我认为应该有更直接的方式。
    【解决方案2】:

    这应该可以正常工作:

    ng-if="::dc.emailNotificationSchedule.progressInterval == dc.SkillCompletionProgressIntervals.NEVER_LOGGED_IN"
    

    你不需要两次双冒号

    【讨论】:

    • 第一个属性前面的冒号只会影响我认为的第一个属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 2010-12-05
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多