1

I have the services and within particular time duration if response is come than ok, other wise show error in popup.

Here is my service code:

angular.module('server', [])

.factory('api', function($http) {
    var server = "http://myapi-nethealth.azurewebsites.net";
        return {
            //Login
            login : function(formdata) {
                return $http({
                    method: 'POST',
                    url: server + '/Users/Login',
                    data: $.param(formdata),
                    headers: { 'Content-Type' : 'application/x-www-form-urlencoded'},
                })
            },
        };

    });

Please tell me how can I use timeout property in services.

4
  • try to use timeout option from $http API docs.angularjs.org/api/ng/service/$http#usage Commented Oct 2, 2014 at 5:01
  • How can I put pop after time out, I have to put in controller or service only... Commented Oct 2, 2014 at 5:07
  • RTFM "Returns a promise object with the standard then method and two http specific methods: success and error." you just need $http({your options}).success(function(){alert('success')}).error(function(){alert('error')}) Commented Oct 2, 2014 at 5:10
  • I don'y know how use the promise, I am using the services in the simple way that I have post in question, can you please tell me how can I use this in my code.....I am new to angularjs Commented Oct 2, 2014 at 5:12

1 Answer 1

1

Read this post - How to set a global http timeout in AngularJs

Where you can set a timeout for your http calls.

You can inject the above factory in your controller and then make a call with success and error callbacks like below

api.login(formdata)
.success(function(){ alert("success"); })
.error(function(){ alert("error"); });
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.