angularjs - How to validate ng-tags-input with promise? -


am trying validate tags added calling server-side api. following code.

 <tags-input ng-model="user.trucks"               add-on-space="true"               on-tag-adding="checktruck($tag)">  </tags-input> 

and in controller have written,

$scope.checktruck = function(tag){   var x = $q.defer();    someservice.checktruck(tag).then(function(response){       x.resolve(true);   }, function(response){       x.reject(false);   });    return x.promise;  }; 

though documentation says on-tag-adding can take promise , validate added tag, it's not working way. missing ??

you know need return values resolve , reject handlers !?

$scope.checktruck = function(tag){     var deferred = $q.defer();      someservice.checktruck(tag).then(function(response){         return deferred.resolve(true);     }, function(response){         return deferred.reject(false);     });      return x.promise;  }; 

we can remove the explicit promise construction you've done there , return resolved or rejected promise hold boolean without deferred object.

$scope.checktruck = function(tag){     return someservice.checktruck(tag).then(function(response){         return $q.when(true);     }, function(response){         return $q.reject(false);     }); }; 

that's how validation

refer $q docs more .when.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -