I am trying to make a modal in Angular 9 that returns a Promise as result. I don't know how to move the promise logic outside of the declaration.
<a class="button-primary" (click)="yes()">Yes</a>
<a class="button-default" (click)="no()">No</a>
This is the modal controller
import { Component, OnInit, HostBinding } from '@angular/core';
@Component({
selector: 'change-username-modal',
templateUrl: './change-username-modal.component.html',
styleUrls: ['./change-username-modal.component.less']
})
export class ChangeUsernameModalComponent implements OnInit {
@HostBinding('class.show')
show: boolean = false;
constructor() { }
ngOnInit(): void {
console.log('init');
}
public open(): Promise<boolean> {
return new Promise(function(resolve, reject) {
resolve(true);
});
}
yes() {
//this.myPromise.resolve(true);
this.show = false;
}
no() {
//this.myPromise.reject(false);
this.show = false;
}
}
I need to make the Promise resolve or reject when calling the yes() or no() functions. Thank you in advance!