An open API service indexing awesome lists of open source software.

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

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