brabertaser1992 brabertaser1992 - 1 year ago 186
Javascript Question

Using Restangular with promises (deferred)

In my app i'm using restangular, and i have such method (which i converted from the plain $http request).
And i don't know how to use correctly restangular with promises. How is it possible?

Here is my code:

var test = function(){
var data = '{"Office":"' + office + '"}';
var deferred = $q.defer();
var person ='persons', id)
$scope.person.patch(data).then(function (response) {
},function (err, status) {
return deferred.promise;

var runIt = function(){

Answer Source

You could simply use promise returned by patch method of instead of creating a new custom promise.


var test = function() {
    var data = '{"Office":"' + office + '"}';
    var person ='persons', id);
    //returned promise
    return person.patch(data).then(function(response) {
    }, function(err, status) {
        return response.status;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download