Two-way binding and interpolation to check “password” and “confirm password”

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question



























    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.







    share|improve this question























      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.







      share|improve this question













      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.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 23 at 0:35









      Jamal♦

      30.1k11114225




      30.1k11114225









      asked Jun 27 at 20:36









      slevin

      1237




      1237

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Python Lists

          Aion

          JavaScript Array Iteration Methods