Skip to content

PendingChangesService

injectable

EditingObserver service is used to track changes made inside the application, that should prevent doing something or going somewhere before the changes are persisted or ignored. For example when the user starts editing form data and tries to navigate away before saving the changes, this service will take care of notifying the user.

It is working kind of like a registry for ongoing tasks that need to be monitored. Every component that needs to be aware of changes to be persisted can start a task and finish it when everything is done.

Other components can ask the service for pending tasks to know whether or not to execute an action (e.g. list component will subscribe and prevent selecting another list item, if changes to the previous one haven’t be finished)

app.component will prevent relevant route changes while tasks are pending.

Returns whether or not the component|service has pending tasks. Checks via confirm dialog

check(component: PendingChangesComponent): boolean
NameTypeDescription
componentPendingChangesComponent
checkForPendingTasks(taskIds: string | string[]): boolean
NameTypeDescription
taskIdsstring | string[]

Clear list of pending tasks

clear(): void

Finishes a task

finishTask(id: string): void
NameTypeDescription
idstring

Returns whether or not the service has pending tasks. If an id is provided, the method will check existence of one specific task.

hasPendingTask(id: string | string[]): boolean
NameTypeDescription
idstring | string[]

Registers a task to be pending.

startTask(message: string): string
NameTypeDescription
messagestring