I have the following service method:
public getConf() : Promise<string[]> {
let rows : string[] = [];
this.dao.getData(SearchCriteria.getRecordsFrom("EcegConfig")).then(configs => {
configs.forEach((cfg : EcegConfRecord) => {
console.log("START", cfg.data.ecegconf);
let tmp = cfg.data.ecegconf;
rows.push(tmp);
});
});
return of(rows).toPromise();}
and the following code block in my component in ngOnInit():
this.http.getConf().then(data => {
console.log("D A T A", data, data.length, data[0]);
});
I can see the correct strings in data, but length is 0 and data[0] is undefined and I can't use forEach on data. Also the START console.log gives me the correct string items.
(I know its maybe unusual that I used return of(rows).toPromise(), I just started with an Observable output, but that should not be the error or? I'm using this in some other methods and it works as intended there)
As I understood the Promise the .then() waits until the return of the service method is complete, or? so data should have elements within it or? So I have maybe a type error somewhere? (But as I said START delivers a correct string and this is the only thing I'm pushing into rows. so Promise return type should be ok or?