title: Angular5 Getting data from observable to component
body: <p>I try to take data from observables to component. </p>
  
  <p>I can not get the data into the array in the typescript, I still get the Observable object and the message of type negatives. However, in HTML the loop correctly prints the data that came.</p>
  
  <p>Services : </p>
  
  
  
  <pre><code>@Injectable()
  export class DataService {
  
      private _dataListSource: BehaviorSubject&lt;Data[]&gt; = new BehaviorSubject&lt;Data[]&gt;([]);
  
  
      constructor(private http: HttpClient) {
      }
  
      getDataList(): Observable&lt;any&gt; {
          return this.http.get&lt;Data[]&gt;('/rest/data/lastDatas').map(res =&gt; {
              this._dataListSource.next(res);
              console.log(res);
          });
      }
  
      subscribeToDatas(): Observable&lt;Data[]&gt; {
          return this._dataListSource.asObservable().distinctUntilChanged();
      }
  
      getData(): Observable&lt;Data[]&gt; {
          return this.http.get&lt;Data[]&gt;('/rest/data/lastDatas');
      }
  }
  </code></pre>
  
  <p>TypeScript class:</p>
  
  <pre><code>export class DataComponent implements OnInit {
  
      dataStatuses: Data[];
  
      public dataList$: Observable&lt;Data[]&gt;;
  
      constructor(public dataService: DataService) {
      }
  
      ngOnInit() {
          this.dataList$ = this.dataService.subscribeToDatas();
          this.dataService.getDataList().subscribe();
          console.log("Informacja ", this.dataList$);
      }
  }
  </code></pre>
  
  <p>HTML : </p>
  
  <pre><code>&lt;div *ngIf="dataList$ | async; let dataList; "&gt;
    &lt;div *ngFor="let data of dataList"&gt;
      {{data.id}}
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>