Two-way binding and interpolation to check âpasswordâ and âconfirm passwordâ

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
Assuming you have an angular template form with a "password" field and a "confirm password" field (usually a register form).
Also assuming that you use two-way binding to bind the form values with the component, which is pretty common and I don't see why not.
So, the simplest, minimal, quickest way to compare the "password" and "confirm password" is to use two-way binding along with interpolation. (I am using Angular 6, but I don't think that does any major difference.)
pass
<input type="password" id="password" [(ngModel)]="password" name="password" #passwordvalidityMsg="ngModel" >
pass confirm
<input type="password" id="confPass" pattern="password" [(ngModel)]="confPass" name="confPass" #confPassvalidityMsg="ngModel" >
<div *ngIf="confPassvalidityMsg.invalid && (confPassvalidityMsg.dirty || confPassvalidityMsg.touched)" >
<div *ngIf="confPassvalidityMsg.errors.pattern"> not the same</div>
</div>
Since there is two-way binding, I can get the password value and put it in the confPass pattern , and then check the pattern as with any other error.
This works for me, but, since I am an Angular newbie, please advise if there is something wrong.
html angular-2+
add a comment |Â
up vote
0
down vote
favorite
Assuming you have an angular template form with a "password" field and a "confirm password" field (usually a register form).
Also assuming that you use two-way binding to bind the form values with the component, which is pretty common and I don't see why not.
So, the simplest, minimal, quickest way to compare the "password" and "confirm password" is to use two-way binding along with interpolation. (I am using Angular 6, but I don't think that does any major difference.)
pass
<input type="password" id="password" [(ngModel)]="password" name="password" #passwordvalidityMsg="ngModel" >
pass confirm
<input type="password" id="confPass" pattern="password" [(ngModel)]="confPass" name="confPass" #confPassvalidityMsg="ngModel" >
<div *ngIf="confPassvalidityMsg.invalid && (confPassvalidityMsg.dirty || confPassvalidityMsg.touched)" >
<div *ngIf="confPassvalidityMsg.errors.pattern"> not the same</div>
</div>
Since there is two-way binding, I can get the password value and put it in the confPass pattern , and then check the pattern as with any other error.
This works for me, but, since I am an Angular newbie, please advise if there is something wrong.
html angular-2+
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Assuming you have an angular template form with a "password" field and a "confirm password" field (usually a register form).
Also assuming that you use two-way binding to bind the form values with the component, which is pretty common and I don't see why not.
So, the simplest, minimal, quickest way to compare the "password" and "confirm password" is to use two-way binding along with interpolation. (I am using Angular 6, but I don't think that does any major difference.)
pass
<input type="password" id="password" [(ngModel)]="password" name="password" #passwordvalidityMsg="ngModel" >
pass confirm
<input type="password" id="confPass" pattern="password" [(ngModel)]="confPass" name="confPass" #confPassvalidityMsg="ngModel" >
<div *ngIf="confPassvalidityMsg.invalid && (confPassvalidityMsg.dirty || confPassvalidityMsg.touched)" >
<div *ngIf="confPassvalidityMsg.errors.pattern"> not the same</div>
</div>
Since there is two-way binding, I can get the password value and put it in the confPass pattern , and then check the pattern as with any other error.
This works for me, but, since I am an Angular newbie, please advise if there is something wrong.
html angular-2+
Assuming you have an angular template form with a "password" field and a "confirm password" field (usually a register form).
Also assuming that you use two-way binding to bind the form values with the component, which is pretty common and I don't see why not.
So, the simplest, minimal, quickest way to compare the "password" and "confirm password" is to use two-way binding along with interpolation. (I am using Angular 6, but I don't think that does any major difference.)
pass
<input type="password" id="password" [(ngModel)]="password" name="password" #passwordvalidityMsg="ngModel" >
pass confirm
<input type="password" id="confPass" pattern="password" [(ngModel)]="confPass" name="confPass" #confPassvalidityMsg="ngModel" >
<div *ngIf="confPassvalidityMsg.invalid && (confPassvalidityMsg.dirty || confPassvalidityMsg.touched)" >
<div *ngIf="confPassvalidityMsg.errors.pattern"> not the same</div>
</div>
Since there is two-way binding, I can get the password value and put it in the confPass pattern , and then check the pattern as with any other error.
This works for me, but, since I am an Angular newbie, please advise if there is something wrong.
html angular-2+
edited Jul 23 at 0:35
Jamalâ¦
30.1k11114225
30.1k11114225
asked Jun 27 at 20:36
slevin
1237
1237
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197377%2ftwo-way-binding-and-interpolation-to-check-password-and-confirm-password%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password