0

I have the following code which sends a request to server validate if the email already exists or not. Its working fine, but the problem is I am using the same directive on modify page. On modify page I want to send another param to server to ignore this email.

.directive('uniqueEmail', function($http) {
        return {
            require: 'ngModel',
            link: function(scope, ele, attrs, c) {
                var ignoreEmail= //here I want to save originol email;
                scope.$watch(attrs.ngModel, function() {
                    $http({
                        method: 'GET',
                        url: '/MY/system/users/checkEmail?'+ $.param({'emailAddress': ele.val(), 'ignoreEmail': ignoreEmail})
                    }).success(function(isUnique,status,headers,cfg) {
                            var iu = isUnique == 'true' ? true : false;
                            c.$setValidity('unique', iu);
                        }).error(function(data,status,headers,cfg) {
                            c.$setValidity('unique', false);
                        });
                });
            }
        }
    });

How can I get the the origonal email in ignoreEmail so that can send to the server

2
  • Just save/remember it once var ignoreEmail=ele.val(); Commented Apr 30, 2014 at 11:20
  • at that point ele.val() is empty Commented Apr 30, 2014 at 11:30

2 Answers 2

1

You can use $eval:

var ignoreEmail = scope.$eval(attrs.ngModel)
Sign up to request clarification or add additional context in comments.

Comments

0

What you can do inside the link function is to save the initial model value, which you can get using ngModelController

var ignoreMail=c.$modelValue;

Now you have the original model value when the link function is called first time.

I have not tried it but it should work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.