SoFunction
Updated on 2025-04-13

Value verification binding method in ngModel of Angularjs

As we all know, in Angular, ngModel is a dynamic two-way binding, and there are two ways.

For example,

Method 1:

In html,

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

In controller

$ = function (searchText) {
 (searchText);
}

Method 2:

Quote *,

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

In html,

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

In the controller,

$ = {};
$ = function () {
 ($.$modelValue);
}

But we often verify the values ​​in ngModel, for example,

&lt;input type="password" pattern="[0-9]*" placeholder="Please enter a new 6-digit password" ng-model="password.new_password" ng-blur="validateLength()"&gt;
<input type="password" ng-model="password.new_password" ng-keyup="compare(password)" name="repassword" ng-pattern="/^[0-9]{1,6}$/" />

It was found that password.new_password in ngModel cannot be bound to the controller in real time, because the value of ngModel does not comply with the pattern rules. If the rules are met, the binding is passed normally.

The above value verification binding method in Angularjs' ngModel is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.