Learning Angular 2 and trying to understand when I should use a component 
input/output and when I should better update a service property (possibly 
attached with an EventEmitter if updates are needed).

I have a list of, say, tasks, and each list items shows various info and 
options for this list item. This list works in the way that only one list 
item is active, and the active one is on the top of the list. One of those 
options for each list item is to activate it (if it is not already active), 
but other components could also possibly change which is the active item.

I have a parent `task` component, `list` component and a `list-item` 
component (and some other related components), and in addition I have a 
`task-service`.

The main `task`component could use `list`component (and `something-realted` 
component, many of the components used needs to know and possibly change 
the `activeItemId`), like this:

    <list [(active-item-id)]=“activeItemId”></list>
    <something-related 
[(active-item-id)]=“activeItemId”></something-related>

The `list`component could use `list-item` this way (`active` is a pipe and 
also a property on item):

    <list-item *ngFor=“#item of items | active” 
               (item)=“item”
               [(active-item-id)]=“activeItemId”>
    </list-item>

But since I have a `task-service` that contains various task related, I 
could use the already existing service property `activeItemId` (with an 
eventemitter), and all the task-components could just get info (and be 
updated) via this property, instead of “sending” the property back and 
forth via various components via inputs/outputs.

When would it be appropriate to just use a service for something like this 
and when would it be appropriate to use input/outputs for components 
instead?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to