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

后端 未结 6 991
别那么骄傲
别那么骄傲 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:41

    Just for completion, here is a code example indicating the differences:

    success \ error:

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

    then:

    $http.get('/someURL')
    .then(function(response) {
        // success handler
    }, function(response) {
        // error handler
    })
    .then(function(response) {
        // success handler
    }, function(response) {
        // error handler
    })
    .then(function(response) {
        // success handler
    }, function(response) {
        // error handler
    }).
    

提交回复
热议问题