国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Angularjs之ngModel中的值驗證綁定方法

2019-11-19 12:57:01
字體:
來源:轉載
供稿:網友

眾所周知,在Angular中ngModel為動態雙向綁定,存在兩種方式。

例如,

方式一:

在html中,

<input type="text" ng-model="searchText" /><button ng-click="check(searchText)">Check!</button>{{ searchText }}

在controller中

$scope.check = function (searchText) { console.log(searchText);}

方式二:

引用stackoverflow的一句話,

“If you use ng-model, you have to have a dot in there.” Make your model point to an object.property and you'll be good to go.

在html中,

<input ng-model="formData.searchText"/><button ng-click="check()">Check!</button>

在controller中,

$scope.formData = {};$scope.check = function () { console.log($scope.formData.searchText.$modelValue);}

但是我們常常會對ngModel當中的值進行驗證,例如,

<input type="password" pattern="[0-9]*" placeholder="請輸入6位新密碼" ng-model="password.new_password" ng-blur="validateLength()">
<input type="password" ng-model="password.new_password" ng-keyup="compare(password)" name="repassword" ng-pattern="/^[0-9]{1,6}$/" />

發現ngModel當中的password.new_password不能實時綁定到controller中,原因為ngModel的值并沒有符合pattern的規則。若符合規則,則正常綁定傳遞。

以上這篇Angularjs之ngModel中的值驗證綁定方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湖州市| 舒城县| 公主岭市| 汝州市| 噶尔县| 瑞丽市| 阿勒泰市| 长汀县| 印江| 永昌县| 洛扎县| 乐昌市| 民和| 安宁市| 定结县| 高要市| 张家港市| 唐河县| 科技| 西吉县| 松江区| 武功县| 仁化县| 清水河县| 庆元县| 岐山县| 拉萨市| 嘉黎县| 安多县| 德兴市| 通化县| 乐至县| 武川县| 错那县| 玉山县| 阿城市| 张家界市| 邵武市| 湘乡市| 白水县| 富源县|