我正在使用Angular 7
,并使用canDeactivate
防护来检查是否未保存“用户编辑的表单”,并且用户尝试单击表单上的另一个选项卡。
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
constructor(private dialogService: DialogService) { }
canDeactivate(component: CanComponentDeactivate, route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const url: string = state.url;
console.log('Url: ' + url);
console.log(component);
return true;
}
}
但是我无法从CanComponentDeactivate的对象中获取任何值。但是,我正在处理的形式是EmployeeComponent。所以我需要输入等级来获取程序相关的属性吗?