0

enter image description hereI am trying to display value of all my fields in a json object .I am able to add firstname ,email , password in an object.but my confirm password not displaying in object why ? I enter same password with confirm password still not display

here is my code

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

angular.module('app', ['ionic','ngMessages']).directive('compareTo',function(){



    return {
        require: "ngModel",
        scope: {
            otherModelValue: "=compareTo"
        },
        link: function(scope, element, attributes, ngModel) {

            ngModel.$validators.compareTo = function(modelValue) {
               // alert(modelValue == scope.otherModelValue)
                return modelValue == scope.otherModelValue;
            };

            scope.$watch("otherModelValue", function() {
                ngModel.$validate();
            });
        }
    };

why confirm password not display ?

}).controller('first',function($scope){

})
user944513
  • 12,247
  • 49
  • 168
  • 318

1 Answers1

0

Your compareTo directive fails and it will not bind to a model if the validator is failing. If you remove your compareTo directive from the code you will get the confiredpassword in your scope.

Refer to this: password-check directive in angularjs to fix your comparTo directive.

Also here is a plunker of the fixed directive: http://plnkr.co/edit/wM3r6eR2jhQS7cjvreLo?p=preview

  .directive('compareTo', function() {
      return {
          scope: {
              targetModel: '=compareTo'
          },
          require: 'ngModel',
          link: function postLink(scope, element, attrs, ctrl) {

              var compare = function() {

                  var e1 = element.val();
                  var e2 = scope.targetModel;

                  if (e2 !== null) {
                      return e1 === e2;
                  }

                  return false;
              };

              scope.$watch(compare, function(newValue) {
                  ctrl.$setValidity('errorCompareTo', newValue);
              });

          }
      };
Community
  • 1
  • 1
Enkode
  • 4,515
  • 4
  • 35
  • 50