Skip to main content
cngx-src documentation

CngxBeforeUnload

DirectivePrimaryv0.1.0

projects/common/interactive/guard/before-unload.directive.ts

Import#

import { CngxBeforeUnload } from '@cngx/common/interactive'

Description#

Prevents accidental page navigation when there are unsaved changes.

Sets a beforeunload event handler that shows the browser's native confirmation dialog when enabled is true. Does NOT integrate with the Angular Router - for route guard protection, use canDeactivateWhenClean().

Protect a form

<form [cngxBeforeUnload]="form.dirty()">

</form>

Combined with route guard

// In route config:
{ path: 'edit', component: EditComponent, canDeactivate: [canDeactivateWhenClean(() => editForm.dirty())] }

// In template:
<form [cngxBeforeUnload]="editForm.dirty()"></form>

Metadata#

Index#

Inputs

Inputs#

enabled#boolean
input()Required

Whether the beforeunload guard is active.

default { alias: 'cngxBeforeUnload' }