Angular returns observable when I call http get method. So I created local server to return 50 MB JSON file which contains all employee data like below.
import { Injectable } from "@angular/core"; import { Http } from "@angular/http"; import 'rxjs/add/operator/map'; @Injectable() export class DataServiceService { constructor(private _http: Http) {} getEmployeeData() { return this._http .get("http://localhost:3000/employees") .map(response => response.json()); } } App.Component.html
{{employeeData$ | async}} They say observable is a stream of data that could change over time.I was under the impression that the whole point of using observable is to start showing the data as soon as stream of employees start returning the data. However in the above example what I witness is that my page is blank for 30 seconds & then suddenly all the employee data starts showing up.
Then what is the point of using observable ? Can't I just load the whole data in a local array & then use that to show it on my HTML ?
Is there any way to achieve the behaviour such as, as soon as it starts recieving the first employee , start rendering it on html... so that user could start seeing the data instead of waiting for 30 seconds.
I understand that in real app I should be fetching only # of employees that user can see in the browser's view & then load the next set of employees.
GET /employees 200 27264.078 ms - -