Any component that needs to use the mechanism needs to tell it when to be triggered and when not to.
example.component.ts
...// import PendingChangesComponent from @valtimoimport { PendingChangesComponent } from'@valtimo/components';...//import modalService and translateService for the Modal to workimport {ModalService} from'carbon-components-angular';import {TranslateService} from'@ngx-translate/core';......// Make the component targetable by the PendingChanges guardexportclassExampleComponentextendsPendingChangesComponent {...// initialize PendingChangesComponentconstructor(private modalService:ModalService,private translateService:TranslateService ) {super(modalService, translateService) }......// let the component know the guard needs to be triggeredpublicexampleDoChange():void { //pendingChanges is an attribute of the PendingChangesComponent that lets it know the guard might need to be triggered
this.pendingChanges =true;... }...// let the component know the changes have been savedpublicexampleSaveChanges():void {...this.pendingChanges =false; }...}
Custom handlers when closing the PendingChanges modal
In case custom handlers need to be added when selecting either Confirm or Cancel, the PendingChangesComponent has two protected methods that can be overwritten for that purpose.
When overwriting these method, the logic inside of them gets triggered right before closing the modal.
example.component.ts
...// import PendingChangesComponent from @valtimoimport { PendingChangesComponent } from'@valtimo/components';...//import modalService and translateService for the Modal to workimport {ModalService} from'carbon-components-angular';import {TranslateService} from'@ngx-translate/core';......// Make the component targetable by the PendingChanges guardexportclassExampleComponentextendsPendingChangesComponent {...// initialize PendingChangesComponentconstructor(private modalService:ModalService,private translateService:TranslateService ) {super(modalService, translateService) }......// overwrite onCancelRedirect methodprotectedonCancelRedirect():void {//custom logic for canceling of navigation }...}