angular1.x開發筆記

$http.post 和 $resource action post的區別


$http.post 使用 $http.post(url, postData, [config]);

params是在config中設置,例如$http.post("#",{"a":1},{params:{}});


resource action post中是

Resource.action([parameters], postData, [success], [error])

這個parameters是顯示申明的,但是是可選參數,也就是說如果url中沒有參數,是可以不帶這個參數的,在action的定義的時候都可以不指定params屬性

但是如果有params,這裏有兩種方式使用,一種params中的數據在postData中沒有,那麼使用的時候就要顯示的帶parameters這個參數,如果是postData中有,那麼可以不帶,直接用postData中的,只是params的定義的時候需要將值通過@符號進行映射

xxxx: {
    method: "post", url: xxxx
}
xxxx: {
    method: "post", url: xxxx,
    params: {formId: ""}
}
xxxx({formId:xxxxx}, formData).then(); //formData中沒有formId這個參數
xxxx: {
    method: "post", url: xxxx,
    params: {formId: "@formId"}
}
xxxx(formData).then(); //formData有formId這個參數



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章