Angular $http difference between .success() and .then()

后端 未结 4 1098
半阙折子戏
半阙折子戏 2021-01-24 23:47

Sometimes I have trouble to fetch my data using $http service. And I did not 100% understand the main difference between .success() and .then()

The following is an examp

4条回答
  •  情书的邮戳
    2021-01-24 23:58

    Success returns data already, in your case it returns cats, so effectively you're assigning property data on cats. On the other hand, in the second example the data are part of the response, so cats are in response.data.

    To understand the difference between $http().then() and $http().success(), I'd recommend this great article: http://chariotsolutions.com/blog/post/angularjs-corner-using-promises-q-handle-asynchronous-calls/

提交回复
热议问题