我想用 canDeactivate 中的 Alertify 确认替换经典确认。我尝试实现以下代码,但单击“确定”时它不返回 True。有人可以就此提出建议吗?
import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { SignupComponent } from 'src/app/signup/signup.component';
import { AlertifyService } from 'src/app/_helpers/alertify.service';
@Injectable()
export class SignUpPUS implements CanDeactivate <SignupComponent> {
constructor(private alertifyService: AlertifyService) {}
canDeactivate(component: SignupComponent) {
if (component.signUpForm.dirty) {
this.alertifyService.confirm('Leave Page', 'Are you sure you want to continue? Any unsaved changes will be lost', () => {
return true;
});
}
return false;
}
}