事件回顾:由于需要修改同一个模板,里面包含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')=}'}}"