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
Post a Comment