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.
Methods
Section titled “Methods”Returns whether or not the component|service has pending tasks. Checks via confirm dialog
check(component: PendingChangesComponent): booleanArguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
| component | PendingChangesComponent |
checkForPendingTasks
Section titled “checkForPendingTasks”checkForPendingTasks(taskIds: string | string[]): booleanArguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
| taskIds | string | string[] |
Clear list of pending tasks
clear(): voidfinishTask
Section titled “finishTask”Finishes a task
finishTask(id: string): voidArguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
| id | string |
hasPendingTask
Section titled “hasPendingTask”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[]): booleanArguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
| id | string | string[] |
startTask
Section titled “startTask”Registers a task to be pending.
startTask(message: string): stringArguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
| message | string |