scope.$eval() is undefined if both input fields have the same directive



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm trying to validate two password input fields. Simply confirm that they are equal. (Suggest another approach if mine is way wrong)



I have implemented a directive with a simple validation that checks if the "confirm" password is the same as the original. But the directive also checks for other things, so I need to have both input fields to have it.



The problem is that when I have my directive on both input fields, I cannot read their model values through the attribute (to check if they match).



Here is a working demo without the directive on the first password:






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope)

);
app.directive('myDir', function()
return
require: 'ngModel',
link: function(scope, elem, attrs, ctrl)
ctrl.$validators.mismatch = function(modelValue, viewValue)
// MAIN CODE:
return viewValue === scope.$eval(attrs.confirm);
;

ctrl.$validators.short = function(modelValue, viewValue)
if (ctrl.$isEmpty(modelValue))
return true;

if (modelValue.length >= 3)
return true;

return false;


;
);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

<form name="form1">
<input type="password" name="password1" ng-model="pass1"><br>
<input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
<pre>form1.password2.$error </pre>
<p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
</form>

</div>





If I change the first filed to:



<input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1">


to validate in both directions, then scope.$eval(attrs.confirm) becomes undefined for both fields.



Here is a demo of my issue:






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope)

);
app.directive('myDir', function()
return
require: 'ngModel',
link: function(scope, elem, attrs, ctrl)
ctrl.$validators.mismatch = function(modelValue, viewValue)
// `scope.$eval(attrs.confirm)` always undefined
return viewValue === scope.$eval(attrs.confirm);
;

ctrl.$validators.short = function(modelValue, viewValue)
if (ctrl.$isEmpty(modelValue))
return true;

if (modelValue.length >= 3)
return true;

return false;


;
);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

<form name="form1">
<input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
<input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
<pre>form1.password2.$error </pre>
<p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
Passwords are different
</p>
</form>

</div>












share|improve this question




























    1















    I'm trying to validate two password input fields. Simply confirm that they are equal. (Suggest another approach if mine is way wrong)



    I have implemented a directive with a simple validation that checks if the "confirm" password is the same as the original. But the directive also checks for other things, so I need to have both input fields to have it.



    The problem is that when I have my directive on both input fields, I cannot read their model values through the attribute (to check if they match).



    Here is a working demo without the directive on the first password:






    var app = angular.module('myApp', );
    app.controller('myCtrl', function($scope)

    );
    app.directive('myDir', function()
    return
    require: 'ngModel',
    link: function(scope, elem, attrs, ctrl)
    ctrl.$validators.mismatch = function(modelValue, viewValue)
    // MAIN CODE:
    return viewValue === scope.$eval(attrs.confirm);
    ;

    ctrl.$validators.short = function(modelValue, viewValue)
    if (ctrl.$isEmpty(modelValue))
    return true;

    if (modelValue.length >= 3)
    return true;

    return false;


    ;
    );

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

    <div ng-app="myApp" ng-controller="myCtrl">

    <form name="form1">
    <input type="password" name="password1" ng-model="pass1"><br>
    <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
    <pre>form1.password2.$error </pre>
    <p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
    </form>

    </div>





    If I change the first filed to:



    <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1">


    to validate in both directions, then scope.$eval(attrs.confirm) becomes undefined for both fields.



    Here is a demo of my issue:






    var app = angular.module('myApp', );
    app.controller('myCtrl', function($scope)

    );
    app.directive('myDir', function()
    return
    require: 'ngModel',
    link: function(scope, elem, attrs, ctrl)
    ctrl.$validators.mismatch = function(modelValue, viewValue)
    // `scope.$eval(attrs.confirm)` always undefined
    return viewValue === scope.$eval(attrs.confirm);
    ;

    ctrl.$validators.short = function(modelValue, viewValue)
    if (ctrl.$isEmpty(modelValue))
    return true;

    if (modelValue.length >= 3)
    return true;

    return false;


    ;
    );

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

    <div ng-app="myApp" ng-controller="myCtrl">

    <form name="form1">
    <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
    <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
    <pre>form1.password2.$error </pre>
    <p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
    Passwords are different
    </p>
    </form>

    </div>












    share|improve this question
























      1












      1








      1








      I'm trying to validate two password input fields. Simply confirm that they are equal. (Suggest another approach if mine is way wrong)



      I have implemented a directive with a simple validation that checks if the "confirm" password is the same as the original. But the directive also checks for other things, so I need to have both input fields to have it.



      The problem is that when I have my directive on both input fields, I cannot read their model values through the attribute (to check if they match).



      Here is a working demo without the directive on the first password:






      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // MAIN CODE:
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
      </form>

      </div>





      If I change the first filed to:



      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1">


      to validate in both directions, then scope.$eval(attrs.confirm) becomes undefined for both fields.



      Here is a demo of my issue:






      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // `scope.$eval(attrs.confirm)` always undefined
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
      Passwords are different
      </p>
      </form>

      </div>












      share|improve this question














      I'm trying to validate two password input fields. Simply confirm that they are equal. (Suggest another approach if mine is way wrong)



      I have implemented a directive with a simple validation that checks if the "confirm" password is the same as the original. But the directive also checks for other things, so I need to have both input fields to have it.



      The problem is that when I have my directive on both input fields, I cannot read their model values through the attribute (to check if they match).



      Here is a working demo without the directive on the first password:






      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // MAIN CODE:
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
      </form>

      </div>





      If I change the first filed to:



      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1">


      to validate in both directions, then scope.$eval(attrs.confirm) becomes undefined for both fields.



      Here is a demo of my issue:






      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // `scope.$eval(attrs.confirm)` always undefined
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
      Passwords are different
      </p>
      </form>

      </div>








      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // MAIN CODE:
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
      </form>

      </div>





      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // MAIN CODE:
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch" style="color:red">Passwords are different</p>
      </form>

      </div>





      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // `scope.$eval(attrs.confirm)` always undefined
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
      Passwords are different
      </p>
      </form>

      </div>





      var app = angular.module('myApp', );
      app.controller('myCtrl', function($scope)

      );
      app.directive('myDir', function()
      return
      require: 'ngModel',
      link: function(scope, elem, attrs, ctrl)
      ctrl.$validators.mismatch = function(modelValue, viewValue)
      // `scope.$eval(attrs.confirm)` always undefined
      return viewValue === scope.$eval(attrs.confirm);
      ;

      ctrl.$validators.short = function(modelValue, viewValue)
      if (ctrl.$isEmpty(modelValue))
      return true;

      if (modelValue.length >= 3)
      return true;

      return false;


      ;
      );

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>

      <div ng-app="myApp" ng-controller="myCtrl">

      <form name="form1">
      <input type="password" my-dir confirm="pass2" name="password1" ng-model="pass1"><br>
      <input type="password" my-dir confirm="pass1" name="password2" ng-model="pass2"><br>
      <pre>form1.password2.$error </pre>
      <p ng-show="form1.password2.$error.mismatch || form1.password.$error.mismatch" style="color:red">
      Passwords are different
      </p>
      </form>

      </div>






      angularjs angularjs-directive angularjs-validation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 12:12









      Aleksey SoloveyAleksey Solovey

      3,5483727




      3,5483727






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You need to do 2 things:
          1. Add ng-model-options="allowInvalid: true" so invalid value will still update scope value.
          2. Now you have problem that e.g. changing 2nd input wont trigger 1st re-validation. This is done using observe:



           <body ng-controller="MainCtrl" ng-init="x = 0; y = 0">
          <form name="form1">
          <input type="password" my-dir="y" confirm="pass2" name="password1" ng-model="pass1" ng-model-options="allowInvalid: true"
          ng-change="x = x + 1"><br>
          <input type="password" my-dir="x" confirm="pass1" name="password2" ng-model="pass2" ng-model-options="allowInvalid: true"
          ng-change="y = y + 1"><br>


          and



          attrs.$observe('myDir', function() 
          ctrl.$validate();
          );


          http://plnkr.co/edit/ws4tVWGXfFNR2yqLRJN7?p=preview



          P.S. for usual fields I would write my-dir="pass1" and then no need in $eval and ng-change, but for passwords... not sure






          share|improve this answer























          • that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

            – Aleksey Solovey
            Nov 15 '18 at 13:42











          • Another way can be: my-dir="password1 === password2"

            – Petr Averyanov
            Nov 15 '18 at 14:17











          Your Answer






          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: "1"
          ;
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319254%2fscope-eval-is-undefined-if-both-input-fields-have-the-same-directive%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You need to do 2 things:
          1. Add ng-model-options="allowInvalid: true" so invalid value will still update scope value.
          2. Now you have problem that e.g. changing 2nd input wont trigger 1st re-validation. This is done using observe:



           <body ng-controller="MainCtrl" ng-init="x = 0; y = 0">
          <form name="form1">
          <input type="password" my-dir="y" confirm="pass2" name="password1" ng-model="pass1" ng-model-options="allowInvalid: true"
          ng-change="x = x + 1"><br>
          <input type="password" my-dir="x" confirm="pass1" name="password2" ng-model="pass2" ng-model-options="allowInvalid: true"
          ng-change="y = y + 1"><br>


          and



          attrs.$observe('myDir', function() 
          ctrl.$validate();
          );


          http://plnkr.co/edit/ws4tVWGXfFNR2yqLRJN7?p=preview



          P.S. for usual fields I would write my-dir="pass1" and then no need in $eval and ng-change, but for passwords... not sure






          share|improve this answer























          • that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

            – Aleksey Solovey
            Nov 15 '18 at 13:42











          • Another way can be: my-dir="password1 === password2"

            – Petr Averyanov
            Nov 15 '18 at 14:17















          0














          You need to do 2 things:
          1. Add ng-model-options="allowInvalid: true" so invalid value will still update scope value.
          2. Now you have problem that e.g. changing 2nd input wont trigger 1st re-validation. This is done using observe:



           <body ng-controller="MainCtrl" ng-init="x = 0; y = 0">
          <form name="form1">
          <input type="password" my-dir="y" confirm="pass2" name="password1" ng-model="pass1" ng-model-options="allowInvalid: true"
          ng-change="x = x + 1"><br>
          <input type="password" my-dir="x" confirm="pass1" name="password2" ng-model="pass2" ng-model-options="allowInvalid: true"
          ng-change="y = y + 1"><br>


          and



          attrs.$observe('myDir', function() 
          ctrl.$validate();
          );


          http://plnkr.co/edit/ws4tVWGXfFNR2yqLRJN7?p=preview



          P.S. for usual fields I would write my-dir="pass1" and then no need in $eval and ng-change, but for passwords... not sure






          share|improve this answer























          • that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

            – Aleksey Solovey
            Nov 15 '18 at 13:42











          • Another way can be: my-dir="password1 === password2"

            – Petr Averyanov
            Nov 15 '18 at 14:17













          0












          0








          0







          You need to do 2 things:
          1. Add ng-model-options="allowInvalid: true" so invalid value will still update scope value.
          2. Now you have problem that e.g. changing 2nd input wont trigger 1st re-validation. This is done using observe:



           <body ng-controller="MainCtrl" ng-init="x = 0; y = 0">
          <form name="form1">
          <input type="password" my-dir="y" confirm="pass2" name="password1" ng-model="pass1" ng-model-options="allowInvalid: true"
          ng-change="x = x + 1"><br>
          <input type="password" my-dir="x" confirm="pass1" name="password2" ng-model="pass2" ng-model-options="allowInvalid: true"
          ng-change="y = y + 1"><br>


          and



          attrs.$observe('myDir', function() 
          ctrl.$validate();
          );


          http://plnkr.co/edit/ws4tVWGXfFNR2yqLRJN7?p=preview



          P.S. for usual fields I would write my-dir="pass1" and then no need in $eval and ng-change, but for passwords... not sure






          share|improve this answer













          You need to do 2 things:
          1. Add ng-model-options="allowInvalid: true" so invalid value will still update scope value.
          2. Now you have problem that e.g. changing 2nd input wont trigger 1st re-validation. This is done using observe:



           <body ng-controller="MainCtrl" ng-init="x = 0; y = 0">
          <form name="form1">
          <input type="password" my-dir="y" confirm="pass2" name="password1" ng-model="pass1" ng-model-options="allowInvalid: true"
          ng-change="x = x + 1"><br>
          <input type="password" my-dir="x" confirm="pass1" name="password2" ng-model="pass2" ng-model-options="allowInvalid: true"
          ng-change="y = y + 1"><br>


          and



          attrs.$observe('myDir', function() 
          ctrl.$validate();
          );


          http://plnkr.co/edit/ws4tVWGXfFNR2yqLRJN7?p=preview



          P.S. for usual fields I would write my-dir="pass1" and then no need in $eval and ng-change, but for passwords... not sure







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 13:17









          Petr AveryanovPetr Averyanov

          6,92411223




          6,92411223












          • that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

            – Aleksey Solovey
            Nov 15 '18 at 13:42











          • Another way can be: my-dir="password1 === password2"

            – Petr Averyanov
            Nov 15 '18 at 14:17

















          • that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

            – Aleksey Solovey
            Nov 15 '18 at 13:42











          • Another way can be: my-dir="password1 === password2"

            – Petr Averyanov
            Nov 15 '18 at 14:17
















          that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

          – Aleksey Solovey
          Nov 15 '18 at 13:42





          that actually gave me an idea to set up a watcher and use $setValidity, instead of using $validators. I think I can still check if they match with return $parse(attrs.confirm)(scope) == ctrl.$modelValue. But in both my and your solutions, it feels like a hack

          – Aleksey Solovey
          Nov 15 '18 at 13:42













          Another way can be: my-dir="password1 === password2"

          – Petr Averyanov
          Nov 15 '18 at 14:17





          Another way can be: my-dir="password1 === password2"

          – Petr Averyanov
          Nov 15 '18 at 14:17



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319254%2fscope-eval-is-undefined-if-both-input-fields-have-the-same-directive%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus