title: How to subscribe object from service in Angular 2/5?
body: <p>I have issue where I want to receive data into my property component after they came from the server. </p>
  
  <p>I made something like this in Service:</p>
  
  <pre><code>private events: Event[] = [];
  eventChanged = new Subject&lt;any&gt;(); // Edit: added an observable
  
  constructor(private http: HttpClient) { 
      this.http.get&lt;Event[]&gt;(this.baseUrl)
      .subscribe(events =&gt; this.events = events);
    this.eventChanged.next(this.events.slice()); //Edit: added an information to subscribers that events list changed
  }
  getEvents(): Observable&lt;Event[]&gt; {
      return this.eventChanged.asObservable();
  }  // Edit: now I use this method to enables subscribers to observable
  
          /* I don't use that method after Edit
          showAllEvents(): Event[] {
              return [...this.events];
          }
          */
  </code></pre>
  
  <p>And then I use method <code>showAllEvents()</code> into mine component like this:</p>
  
  <pre><code>private events: Event[] = [];
  private calendarEvents: CalendarEvent[] = [];
  subscription: Subscription; // Edit: Added a Subscription
  
      getInterestedEvents() {
         // this.events = this.el.showAllEvents(); &lt;-- I changed it into observable
     this.subscription = this.el.getEvents()
      .subscribe(
      (events) =&gt; {
        this.events = events;
      });
      this.events.forEach(eachEvent =&gt; {
          let calendarEvent: CalendarEvent = {
              start: subDays(startOfDay(new Date()), 1),
              end: addDays(new Date(), 1),
              title: eachEvent.name,
              color: colors.red
          }
          this.calendarEvents.push(calendarEvent);
      })
  }
  </code></pre>
  
  <p>I don't know how to make <code>this.events</code> to wait for data from service. Any ideas? On every page it looks different and now I feel like a fool.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I made a subscribe and observable but still <code>this.el.getEvents().subscribe...</code> dosen't return any data in my component. </p>