I have a setup in which I am calling a directive to check username-availability, but I want it to execute when user click on the input field for adding new username on Registeration(modal). But ng-keyup does not seem to work, can Anyone help what is the issue.
myApp.directive('usernameAvailable',function ($timeout, $q, $http,apiUrl) {
            return {
            restrict: 'AE',
            require: 'ngModel',
            link: function (scope, elm, attr, model) {
                scope.$watch(attr.ngModel, function(uname) {
                    /*Validate user name ajax call*/
                    $http({
                        method: "GET",
                        url: apiUrl+"getUserNameValidated",
                        contentType: "application/json",
                        dataType: "json",
                        timeout: 180000,  //180 sec
                        params: {'username': uname}
                    }).success(function(res){
                        sessionStorage.setItem('unameAvailability',res.msg);
                        $timeout(function(){
                            if(res.msg=="Success"){
                                model.$setValidity('usernameExists', true);
                            }else{
                                model.$setValidity('usernameExists', false);
                            }
                        }, 1000);
                    }).error(function (x, t, m) {
                        swal("Error connecting to server");
                        if (t === "timeout") {
                            swal("timeout");
                        } else {
                            //alert(t);
                        }
                    });
                });
            }
        }
    });
<div class="col-md-5">
  <input type="text" name="userName"
         ng-model="registerAppCtrl.registerAppDetails.user.uname" 
         id="reg-uname" class="form-control" tabindex="5"
         placeholder="User Name" username-available />
 </div>
It is no way related to validation, it is related to calling directive based on some condition( if it is one of the ways).
I hope people get it.
