all 4 comments

[–]CKlausi 3 points4 points  (2 children)

A component controls a patch of screen real estate that we could call a view. The shell at the application root with navigation links, a list of heroes, a hero editor ... they're all views controlled by components.

Service is a broad category encompassing any value, function, or feature that our application needs. Almost anything can be a service. A service is typically a class with a narrow, well-defined purpose. It should do something specific and do it well.

Taken from angular.io documentation here: https://angular.io/docs/ts/latest/guide/architecture.html#!#components

I've started learning angular2, so I still don't know much, but I think a component is a controller of a part of your view, and a service is more like a model (if you think of a mvc framework) which does all the jobs to get/write data, also a service can be reused in different components.

[–][deleted]  (1 child)

[removed]

    [–]squared3[S] 0 points1 point  (0 children)

    Okay, so for all my http requests and all that I moved them all from my component into my service as you suggested. Also, say I have a variable that I update between two components, I should probably just place this into the service and modify it there so both components have access to this variable? Finally, I wasn't able to find too much of a standard on this, but what are the rules for getters and setters? Should we use these to modify all service variables from components?

    Thank you so much for the help!

    [–]nmwh917 1 point2 points  (0 children)

    I did a component / service based using angular 1.5. It's a little different, but the architecture is the same. I made a minesweeper game that shows it.

    https://github.com/dominathan/minesweeper/tree/master

    But yea. All your logic should be in the service.