角赫特普羅:“成功”/“錯誤”方法與“那”論據的區別根據安古拉JS醫生,呼叫$http返回以下內容:返回承諾對象使用標準然后方法和兩個特定于http的方法:成功和誤差..這個然后方法使用兩個參數成功和一個誤差回調,它將使用響應對象調用。這個成功和誤差方法采用單個參數-在請求成功或失敗時將分別調用該函數。傳遞給這些函數的參數是傳遞給當時方法的響應對象的非結構化表示。除了response對象在一種情況下是非結構化的,我不知道的參數傳遞的成功/錯誤回調。promise.then類的參數傳遞給回調。promise.success/promise.error承諾的方法有嗎?這兩種不同的方式傳遞看似相同的回調有什么意義?
3 回答

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
鈮
.then()
.success()
.then()
.success()
.then()
-承諾API的全部功能,但稍微詳細一些 .success()
-不回承諾,但略帶約束的語法

ABOUTYOU
TA貢獻1812條經驗 獲得超5個贊
success()
返回原來的承諾 then()
回報一個新的承諾
then()
$http.get(/*...*/). then(function seqFunc1(response){/*...*/}). then(function seqFunc2(response){/*...*/})
$http.get()
seqFunc1()
seqFunc2()
success()
$http(/*...*/). success(function parFunc1(data){/*...*/}). success(function parFunc2(data){/*...*/})
$http.get()
parFunc1()
,parFunc2()
并行

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
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});
success
/error
:
$http.get('/someURL').success(function(data, status, header, config) { // success handler}).error(function(data, status, header, config) { // error handler});
- 3 回答
- 0 關注
- 402 瀏覽
添加回答
舉報
0/150
提交
取消