https://github.com/fvilers/ngx-ordered-initializer
An Angular DI token that you can use to provide one or more initialization functions that will be executed in order
https://github.com/fvilers/ngx-ordered-initializer
angular dependency-injection initializer
Last synced: 12 months ago
JSON representation
An Angular DI token that you can use to provide one or more initialization functions that will be executed in order
- Host: GitHub
- URL: https://github.com/fvilers/ngx-ordered-initializer
- Owner: fvilers
- License: mit
- Created: 2020-12-17T09:42:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T15:21:56.000Z (over 2 years ago)
- Last Synced: 2025-04-09T20:06:55.280Z (12 months ago)
- Topics: angular, dependency-injection, initializer
- Language: TypeScript
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ngx-ordered-initializer
An Angular DI token that you can use to provide one or more initialization functions that will be executed in order
## Installation
```
npm install ngx-ordered-initializer
```
## Versions
- Angular 11: 1.0.0
- Angular 12: 2.0.0
- Angular 14: 4.0.0
- Angular 15: 5.0.0
- Angular 16: 6.0.0
## Usage
```
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {
ORDERED_APP_INITIALIZER,
ORDERED_APP_PROVIDER,
} from 'ngx-ordered-initializer';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, HttpClientModule],
providers: [
{
provide: ORDERED_APP_INITIALIZER,
useFactory: initializer1,
multi: true,
},
{
provide: ORDERED_APP_INITIALIZER,
useFactory: initializer2,
multi: true,
},
ORDERED_APP_PROVIDER,
],
bootstrap: [AppComponent],
})
export class AppModule {}
```
The `ORDERED_APP_PROVIDER` will ensure that each initializer provided as `ORDERED_APP_INITIALIZER` will be executed in the declaration order.
## Demo
https://stackblitz.com/edit/ngx-ordered-initializer-demo