I'm trying to get value from inside to outside then using promise.
In my controller I have:
async Sample(userId: number)
{
let data = this.userService.getAffectedExpertisesPromise(userId);
await data.then((uri) =>
{
uri.forEach((exp: Expertise) =>
{
this.empList.push(exp.name);
});
})
return this.empList;
}
On ngOnInit, I call this function:
this.Sample(25).then(item =>
{
item.forEach((expLibelle: String) =>
{
listExp.push(expLibelle);
});
console.log("------------------------ List Size Inside: " + listExp.length);
});
console.log("------------------------ List Size Outside : " + listExp.length);
In service user file, I have:
getAffectedExpertisesPromise(id: number): Promise<any>
{
return this.http.get(`${this.baseUrl}/users/expertisesObj/${id}`).toPromise();
}
It produces:
------------------------ List Size Outside : 0
------------------------ List Size Inside: 3
As you saw:
- the size inside
then
is 3 --> Correct answer - the size inside
then
is 0 --> Wrong answer
Could you please help me solving that issue ?.
Big thanks.