第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在自定義指令中獲取評估屬性

如何在自定義指令中獲取評估屬性

鳳凰求蠱 2019-07-31 11:28:00
如何在自定義指令中獲取評估屬性我試圖從我的自定義指令獲取一個(gè)評估屬性,但我找不到正確的方法。我已經(jīng)創(chuàng)建了這個(gè)jsFiddle來詳細(xì)說明。<div ng-controller="MyCtrl">     <input my-directive value="123">     <input my-directive value="{{1+1}}"></div>myApp.directive('myDirective', function () {     return function (scope, element, attr) {         element.val("value = "+attr.value);     } });我錯(cuò)過了什么?
查看完整描述

3 回答

?
胡說叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

對于我正在尋找的相同解決方案Angularjs directive with ng-Model。 
這是解決問題的代碼。 

    myApp.directive('zipcodeformatter', function () {
    return {
        restrict: 'A', // only activate on element attribute
        require: '?ngModel', // get a hold of NgModelController
        link: function (scope, element, attrs, ngModel) {

            scope.$watch(attrs.ngModel, function (v) {
                if (v) {
                    console.log('value changed, new value is: ' + v + ' ' + v.length);
                    if (v.length > 5) {
                        var newzip = v.replace("-", '');
                        var str = newzip.substring(0, 5) + '-' + newzip.substring(5, newzip.length);
                        element.val(str);

                    } else {
                        element.val(v);
                    }

                }

            });

        }
    };});


HTML DOM

<input maxlength="10" zipcodeformatter onkeypress="return isNumberKey(event)" placeholder="Zipcode" type="text" ng-readonly="!checked" name="zipcode" id="postal_code" class="form-control input-sm" ng-model="patient.shippingZipcode" required ng-required="true">


我的結(jié)果是:

92108-2223


查看完整回答
反對 回復(fù) 2019-07-31
  • 3 回答
  • 0 關(guān)注
  • 641 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號