Reputation: 972
I can´t handle res in array form by httpClientModule. The Api is created by NodeJS. A easy try looks like that:
res.send( [ { message: 'lego api!' } , { name: 'lucy' } ] );
The response works when i test it by my browser. No i wants to use the same url in Angular. For I imported the httpClientModule in app.module. The app component looks like that:
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
ngOnInit(): void {
console.log(this.list());
}
list(): Observable<any> {
return this.http.get('http://localhost:8080/api').map(data => data.message);
}
In console i only get the informations of the observable:
Observable {_isScalar: false, source: Observable, operator: MapOperator} operator : MapOperator {project: ƒ, thisArg: undefined}
source : Observable {_isScalar: false, source: Observable, operator: MapOperator}
_isScalar : false
proto : Object
I dont get what i´m doing wrong.
Upvotes: 0
Views: 1034
Reputation: 149
You need to subscribe to your Observable.
An HttpClient method does not begin its HTTP request until you call subscribe() on the observable returned by that method.
Upvotes: 2