Should I use angularjs $http service for requests or jquery ajax if possible?

后端 未结 4 1993
渐次进展
渐次进展 2021-01-06 07:28

In my project, I use angularjs framework and love using the $http service whenever I make an ajax call. But in parts of the project, where an UI is not directly

4条回答
  •  孤城傲影
    2021-01-06 07:46

    I would personally recommend keeping it consistent with a common service layer that encapsulates http requests. While you can mix it up I only recommend doing that if you are dealing with code that has already been written with jquery. Also, if you end up wanting to change it later to update the UI, you would have to go back and change the jquery calls.

    Another point that was already made by Blaise is that $http really shines if you are doing unit testing and want to mock responses. Here is an example of this: http://www.unit-testing.net/CurrentArticle/How-to-mock-http-calls-in-Angular.html

提交回复
热议问题