Skip to content Skip to sidebar Skip to footer

Post From Api With Basic Authentication

I can't download data from the API I'm doing something wrong but I don't know what const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', '

Solution 1:

Observables are lazy, they won't execute unless you subscribe to them.

So basically you've to subscribe to observable in order to make the http call in action. Currently when you do console.log you can see thorough observable inside browser console. Basically when subscribe to function http call gets executed and underlying subscribe function get triggered where you can assign the value of myEligibilityData

myEligibilityData;

this.coverageService.getEligibilityData(bodyEligibility).subscribe(data => {
    console.log(data);
    this.myEligibilityData = data;
});

And if you wanted to display this data directly onto the HTML then you can keep your existing code as is. You don't have to subscribe observable, instead use async pipe on HTML, it will take care of apply subscribe and extract data from the Observable.

<ng-container *ngIf="myEligibilityData$ | async as myEligibilityData">
   {{myEligibilityData | json}}
</ng-container>

Post a Comment for "Post From Api With Basic Authentication"