I am working with an observable of type 'ICase' which retrieves data from a JSON file through a method in the service file. The template-service.ts file contains the following code:
private _caseUrl = 'api/cases.json';
getCases(): Observable<ICase[]>
{
return this._http.get(this._caseUrl)
.map((response: Response) => <ICase[]> response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
In the template component, I am trying to display the length of the observable array. Despite attempting to use the async pipe and the .length operator, I have not been successful in displaying it on the DOM. The template.component.ts file includes the following code:
ngOnInit(): void
{
console.log("---In OnInit---");
this._templateService.getCases()
.subscribe(cases => this.cases = cases, error=> this.errorMessage = <any>error);
console.log('Num of cases: ' + this._templateService.getCases().map.length);
}
The provided HTML showcases the display of observable elements while keeping specific data hidden for privacy purposes. Red circles highlight the areas where I am attempting to show the length of the observables. Browser Image