AngularJs 三目运算 表达式判断

事件回顾:由于需要修改同一个模板,里面包含2个不同的内容,第一个里面使用的时间差和第二个里面名称不一样,其他过滤器,内容都大同小异。希望杜绝If这样比较傻的来判断if-show or not,继续追究其源码。

var b = "{{",
      a = "}}";
        this.startSymbol = function(a) {
            return a ? (b = a, this) : b
        };
        this.endSymbol = function(b) {
            return b ? (a = b, this) : a
        };

var Ca = b.startSymbol(),
                    oa = b.endSymbol(),
                    Z = "{{" == Ca || "}}" == oa ? Fa : function(a) {
                        return a.replace(/\{\{/g, Ca).replace(/}}/g, oa)
                    }, W = /^ngAttr[A-Z]/;
                return z

 

源码剖析:其实就是把angularjs特有的{{}}符号替换掉,里面的内容接着在转成js继续处理,所以里面的表达式各种你都可以使用js特有的属性啊,内置函数啊操作它。它就是这么神奇。

 

使用指南:

<span class="remaining-time">{=__('directives_market.sl_loan_card.remain_time')=}
{{ loan.loanTimeRemaining||loan.listingTimeLeft | slRemainingTime }}
</span>

 

{{ev.email ? "{=__('validation')=}" : 
"{=__('account.summary.account_profile.bind_data')=}"}}

 

复杂型三目运算:

<input type="text" class="form-control email input-sm" id="account-email" name="email" ng-class="{inputError:userEmail.emailError}"
               ng-model="userEmail.email" required placeholder="{{userEmail.isVerified ? '{=__("account.summary.account_profile.input_new_email")=}' : '{=__("account.summary.account_profile.input_email_address")=}'}}" autocomplete="off" sl-email/>


placeholder="{{cellphoneVerification.isVerified ? '{=__('account.summary.account_profile.input_new_mobile_number')=}' : '{=__('account.summary.account_profile.input_mobile_number')=}'}}"

 

 

 

继续学习:http://each.sinaapp.com/angular/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值