title: Pass object property to service from component, or not to?
body: <p>I'm fairly new to Observables, Promises, Angular 2 and trying to understand architecture and best practices.</p>
  
  <p>I have an app component that looks like this:</p>
  
  <pre><code>export class AppComponent {
  
    items: Item[] = // some Items in here
    totalSalesLastThirtyDays: number = 0
  
    constructor (private itemTransactionsService: ItemTransactionsService) {}
  
    ngOnInit() { 
      this.itemTransactionsService.getLastThirtyDays(this.items)
    }
  }
  </code></pre>
  
  <p>I have a service that looks like this:</p>
  
  <pre><code>@Injectable()
  export class ItemTransactionsService {
  
    constructor (private http: Http) {}
  
    getLastThirtyDays(items: Item[]) {
      /// How do I know when all the observables have completed
      /// and I can compute the totalSalesLastThirtyDays?
      /// Where would I set totalSalesLastThirtyDays property of AppComponent?
      for (let item of items) {
          this.getItemTransactions(item).subscribe(result =&gt; {
                          // console.dir("result = " + result);
                          item.soldInLast15Days = result[0]
                          item.soldInLast30Days = result[1]                      
                        },
                        error =&gt;  {})
      }
    }
  
  
  
    getItemTransactions(item: Item): Observable&lt;any&gt; {
      // Work work work
      return this.http.post(this.url, body, options)
                      .map(this.extractData)
                      .catch(this.handleError);
    }
  }
  </code></pre>
  
  <p>Ultimately, when all the getItemTransactions have been invoked and returned on each item, I want to compute the totalSalesLastThirtyDays, where totalSalesLastThirtyDays is a property on my AppComponent.</p>
  
  <p>What would be the "Angular 2" architectural way of getting this done?</p>
  
  <p>Do I pass the totalSalesLastThirtyDays by reference to the service?
  Do I use an observable on getLastThirtyDays to pass back a computed totalSalesLastThirtyDays to be set in the AppComponent?
  How do I know that all the API calls in the for-loop have completed and I can compute the totalSalesLastThirtyDays?</p>
  
  <p>I'm not sure what would be a good title for this question - so please suggest if you can think of one.</p>