0

When I save my data using angular service factory, how do I handle the timeout event, lets say if the internet connection is unstable, now I end up with a loading screen infinitely, so I want to set timeout after few seconds if the response is not received, my rest service looks like this:

.factory('Deal', [ '$resource', function($resource) {
    return $resource("/deals/:id/:action.json", {
        id : "@id",
        action : "@action"
    }, {
        query : {
            method : "GET",
            isArray : false
        },
        update : {
            method : "POST",
            params : {
                    action : 'update'
            }
        }
    });
} ])

And this is how I call the save method:

  Deal
    .save(
        $scope.deal,
        function(data) {
        },
        function(err) {
        });
1

1 Answer 1

2

The configuration option has a timeout property that may help you

query : {
        method : "GET",
        isArray : false,
        timeout:5000, //In millisecond
    },

You can use the $http.defaults configuration to override this at global level. See documentation on $http or $resource https://code.angularjs.org/1.3.3/docs/api/ng/service/$http

When the timeout lapses the underlying resource promise will be rejected and you willland on error callback

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.