So, I was trying to get the solution of this problem by using async/await. But, I am unable to do so, May be because of the lack of knowledge in angular. I have to access response values assigned in async fetchData() in component
The default values assign to employee is ALL
async function in component :
async fetchData(empId:string, empUrl:string) {
this.message = "Fetching..";
this.resp = await this.http
.get<any>(empUrl+empId)
.toPromise();
this.message = "Fetched";
}
function call :-
getEmployeeById(empId:string, empUrl:string){
console.log("Get employee by empId....");
console.log("Before calling Employee API Call:");
for (var obj of this.empResp) {
console.log("empId : " +obj.empId);
console.log("empName : " +obj.empName);
}
console.log("************calling asynch call");
this.fetchData(empId, empUrl);
console.log("************back");
console.log("After calling Employee API Call:");
for (var obj of this.empResp) {
console.log("empId : " +obj.empId);
console.log("empName : " +obj.empName); }
}
on new employee values I have apply filters but not able to get the values out side async call.
Console OutPut :-
app.component.ts:65 Get employee by empId....
app.component.ts:66 Before calling employee API Call:
app.component.ts:68 empId : ALL
app.component.ts:70 empName : ALL
app.component.ts:72 ************calling asynch call
app.component.ts:74 ************back
app.component.ts:76 After calling employee Archive API Call:
app.component.ts:78 empId : ALL
app.component.ts:80 empName : ALL
app.component.ts:61 (3) [{…}, {…}, {…}]0: {empId: "123", empName: "XYZ"}1: {empId: "324", empName: "ABC"}length: 2__proto__: Array(0)
so after this run I want employees value as shown in response.
Please suggest.