0

I am taking two different classes on Udemy and started with angular2 so I understand ng2's service approach. Now I'm learning angular 1, can someone clarify angular1's $http service for me? Do I use it in a custom service? or is it the service that goes within a controller? Basically what's the best practice for a non crud $http GET of json

3
  • You can do either but I think most people would recommend that you use it in a custom service. Commented Jul 20, 2016 at 0:39
  • So do I inject the HTTP service object? all the custom service examples I see don't have dependency injection, they just look like normal functions Commented Jul 20, 2016 at 1:13
  • Yes, inject $http where you need to use it....service, controller or directive etc Commented Jul 20, 2016 at 2:46

1 Answer 1

2

The common agreed upon best practice is to separate all your $http requests from your controllers in a service/factory.

This guide is great if you've got a good grasp on Javascript but are looking for some best practice suggestions for Angular 1.x:

https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#defer-controller-logic-to-services

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.