javascript - Username Check with return object directive -


i'm trying implement usercheck directive return user object success user checking. i'm unable bind return object model once complete user check mistake have done. directive follow

app.directive('usernameavailable', function($timeout, $q, $http) {   return {     restrict: 'ae',     require: 'ngmodel',     link: function(scope, elm, attr, model) {        model.$asyncvalidators.usernameexists = function() {          return $http.get('backend.json').then(function(res){+           $timeout(function(){             var data = res.data;              model.$setvalidity('usernameexists', !!data.valid);             model.usermodel = res.user;             scope.$apply();           }, 1000);         });          };     }   }  }); 

here plunker

thanks

i fixed plunker. hope helps... used .success instead of .then , wrote user object scope.

remark: in example working fine, write directive it's own scope user object wouldn't visible.

link: function(scope, elm, attr, modelcontroller) {   modelcontroller.$asyncvalidators.usernameexists = function() {     return $http.get('backend.json').success(function(data) {       $timeout(function() {         modelcontroller.$setvalidity('usernameexists', !!data.valid);         scope.user = data.user;       }, 1000);     });   }; } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -