2016-07-28 129 views
2

我想問一下關於這個方法的區別 我關心的是.then和.success之間的區別,函數也是.error 謝謝。

// Simple GET request example: 
$http({ 
    method: 'GET', 
    url: '/someUrl' 
}).then(function successCallback(response) { 
    // this callback will be called asynchronously 
    // when the response is available 
}, function errorCallback(response) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
}); 

// Simple GET request example: 
$http({ 
    method: 'GET', 
    url: '/someUrl' 
}).success(function successCallback(response) { 
    // this callback will be called asynchronously 
    // when the response is available 
}).error(function(data) { 
    // called asynchronously if an error occurs 
    // or server returns response with an error status. 
}); 
+1

http://www.syntaxsuccess.com/viewarticle/angular-promises%E2%80%93then-vs-success –

+2

不要使用成功和錯誤,然後使用和捕捉。 – dfsq

+3

'.success'和'.error'已棄用。 – Claies

回答

5

兩個.then().sucess()是指保證它異步運行,並等待迴應則否reject fullfied您的請求,那麼它resolve它。

.success.error已被棄用,你可以找到關於文檔的更多信息