Open web-dave opened 4 years ago
ng g guard fleet/leave
@Injectable({providedIn: 'root'})
export class LeaveGuard implements CanDeactivate<VehicleNewComponent> {
canDeactivate(target: VehicleNewComponent) {
if (!target.isSaved()) {
return window.confirm('Do you really want to cancel?');
} else {
return true;
}
}
}
{
path: 'new',
component: VehicleNewComponent,
canDeactivate: [LeaveGuard]
}
// this.saved needs to be set on Save
isSaved() {
return this.saved || !this.form.dirty;
}
leave
guardnew
route