0

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.

1 Answer 1

2

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.

docs

Sign up to request clarification or add additional context in comments.

1 Comment

i can´t believe that i missed the subscribe. Anyway thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.