I have 3 functions. And I want to call the other function after a function is completed. In my first function, I am setting a variable(students) in the page. And the second function uses that variable. So I am using promise. But I tried a lot of ways. But I can't execute the code with promise. I want, in my buttonClick, my three functions should work orderly async. I want like below. How can I do?
students: [];
studentInfoList: [];
otherList: [];
buttonClick() {
const myPromise = new Promise(function (resolve, reject) {
myFirstOperation();
});
myPromise()
.then(result => {
mySecondOperation();
})
.then(result => {
myThirdOperation();
});
}
myFirstOperation() {
this.studentService.getStudents().subscribe(
result => {
this.students = result.data;
});
}
mySecondOperation() {
for (let student of this.students) {
this.studentInfoList.push({ studenNameSurname=student.Name + student.Surname });
}
}
myThirdOperation() {
for (let studentInfo of this.studentInfoList) {
this.otherList.push(this.studentInfoList);
}
}