I need to run two if blocks consecutively in TypeScript, with the second block depending on a flag set by the first block. The code below illustrates my scenario:
export class Component {
condition1: boolean;
constructor(private confirmationService: ConfirmationService) {}
submit() {
this.condition1 = false;
if (somecondition) {
if (this.condition1 == false) {
this.confirmationService.confirm({
message: "Do you want to proceed?",
accept() {
// Redirect to another page
},
reject() {
this.condition1 = true;
}
});
}
if (this.condition1 == true) {
this.confirmationService.confirm({
message: "Do you want to quit?",
accept() {
// Perform certain action
},
reject() {
// Perform certain action
}
});
}
}
}
}
Upon clicking the SUBMIT button, a confirm dialog box is displayed. The message in the box depends on the condition set. If the condition one is false, the first message is shown. Upon clicking YES or NO in the dialog box, either the accept() or reject() function is called respectively. In the reject() function, condition1 is set to true. Once condition1 is true, the current dialog should close and immediately open again with a different message based on the outcome of the second if block. How can I achieve this?