日々精進

新しく学んだことを書き留めていきます

Angularの$http.get(...).successと$http.get(...).thenでは渡される引数が違う

ちょっと勘違いしていたんだけど、successの定義は以下のようになっていてdataにhttp bodyが入る。

success(data: any, status: number, headers: ng.IHttpHeadersGetter, config: ng.IRequestConfig)

thenの場合は以下のようにresponseが引数として渡される。response.dataにhttp bodyが入る。successの引数も入っている。例えばstatusはresponse.statusに入っている。

then(response: any)

http bodyにdataなんて項目ないのになぜresponse.dataが。。となってしまった。

参考: