This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HostListener('window:beforeunload', ['$event']) | |
unloadNotification($event: any) { | |
if (this.hasUnsavedData()) { | |
$event.returnValue =true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class CanDeactivateGuard implements CanDeactivate<UserFormComponent> { | |
canDeactivate(component: UserFormComponent): boolean { | |
if(component.hasUnsavedData()){ | |
if (confirm("You have unsaved changes! If you leave, your changes will be lost.")) { | |
return true; | |
} else { | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{path:'user/new',component:UserFormComponent,canDeactivate: [CanDeactivateGuard]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {HostListener} from "@angular/core"; | |
export abstract class ComponentCanDeactivate { | |
abstract canDeactivate(): boolean; | |
@HostListener('window:beforeunload', ['$event']) | |
unloadNotification($event: any) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ComponentCanDeactivate} from '../can-deactivate/component-can-deactivate'; | |
import {NgForm} from "@angular/forms"; | |
export abstract class FormCanDeactivate extends ComponentCanDeactivate{ | |
abstract get form():NgForm; | |
canDeactivate():boolean{ | |
return this.form.submitted || !this.form.dirty | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class CanDeactivateGuard implements CanDeactivate<ComponentCanDeactivate> { | |
canDeactivate(component: ComponentCanDeactivate): boolean { | |
if(!component.canDeactivate()){ | |
if (confirm("You have unsaved changes! If you leave, your changes will be lost.")) { | |
return true; | |
} else { | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p-listbox *ngIf="!dropdownButton" | |
[disabled]="disabled" | |
[options]="options" | |
[ngModel]="selectedItems" | |
(onChange)="onValueChange($event.value)" | |
[multiple]="true" | |
[checkbox]="true" | |
[filter]="filter" | |
[showToggleAll]="showToggleAll" | |
[metaKeySelection]="false"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[requiredIf]', | |
providers: [ | |
{provide: NG_VALIDATORS,useExisting:RequiredIfDirective, multi: true} | |
] | |
}) | |
export class RequiredIfDirective implements Validator { | |
@Input("requiredIf") | |
requiredIf: boolean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Validator { | |
validate(c: AbstractControl): ValidationErrors | null; | |
registerOnValidatorChange?(fn: () => void): void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registerOnValidatorChange(fn: () => void): void { this._onChange = fn; } | |
private _onChange: () => void; | |
ngOnChanges(changes: SimpleChanges): void { | |
if ('requiredIf' in changes) { | |
if (this._onChange) this._onChange(); | |
} |
OlderNewer