Angular HttpPromise: difference between `success`/`error` methods and `then`'s arguments

后端 未结 6 995
别那么骄傲
别那么骄傲 2020-11-22 16:59

According to AngularJS doc, calls to $http return the following:

Returns a promise object with the standard then

6条回答
  •  自闭症患者
    2020-11-22 17:37

    Some code examples for simple GET request. Maybe this helps understanding the difference. Using then:

    $http.get('/someURL').then(function(response) {
        var data = response.data,
            status = response.status,
            header = response.header,
            config = response.config;
        // success handler
    }, function(response) {
        var data = response.data,
            status = response.status,
            header = response.header,
            config = response.config;
        // error handler
    });
    

    Using success/error:

    $http.get('/someURL').success(function(data, status, header, config) {
        // success handler
    }).error(function(data, status, header, config) {
        // error handler
    });
    

提交回复
热议问题