我在Angular项目中有一个表单,其中我尝试实现自定义模式弹出窗口,而不是使用确认对话框,该对话框在客户填写表单时以及在尝试退出表单之间出现。表格,然后会出现一个自定义模式,并显示一条消息,要求y / n退出
为此,我通过访问组件类中的angular模板引用变量在Angular中使用了CanDeactivate路由保护。
我将ts代码放在下面
import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { CreateEmployeeComponent } from './create-employee.component';
@Injectable()
export class CreateEmployeeCanDeactivateGuardService implements CanDeactivate<CreateEmployeeComponent> {
constructor() { }
canDeactivate(component: CreateEmployeeComponent): boolean {
if (component.createEmployeeForm.dirty) {
return confirm('Are you sure you want to discard your changes?');
}
return true;
}
}
如您所见,代码包含js内置函数validate(),return confirm('Are you sure you want to discard your changes?');
**I want to replace this with a custom modal popup how can I do that**
答案 0 :(得分:0)
对于上述问题,我尝试使用ngx-bootrap模态,并且模型运行正常