I have a method getClients which is a call to a webservice giving back a Json answer with one of the fields is "response" ( giving all clients back as interface Data[] )
getClients(): Observable<any> {
// Get all clients from the database
return this.http.get<any>(environment.apiURL + '/client/list' );
}
I have in another component a method getResults() :
filterData: Data[];
getResults(): Promise<Data[]> {
const promise = new Promise<Data[]>((resolve, reject) => {
this.restApiService.getClients()
.toPromise()
.then( clients => {
clients.response.json as Data[];
})
.catch(this.handleError);
;
});
return promise;
}`
=> return promise; <= instead here I would like to "return this.filterData;" with just the data I need from promise as interface Data[]
Another component : receiving the results, here I would like it be the interface Data[]
clients: Promise<Data[]>;
constructor( private service: Service ) {
this.clients = this.service.getResults();
console.log('clientsssss : ' + this.clients);
}
ngOnInit() {
}
The interface Data - this is the structure in the field "response"
export interface Data {
clientName: string;
clientId: number;
}
I don't succeed to get back from the method getResults the data I need ( interface Data )
I tried first as with the Observable, but it is a long list and it doesn't give any results ( empty ), so I read it is async so I need to use "promise".