The source code:

import {StoreModule} from '@ngrx/store';
import {reducers} from './reducer';
import { NgModule } from '@angular/core';
import { CounterComponent } from './container/component/counter/counter.component';
import { CommonModule } from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { BookManageComponent } from './container/component/bookmanage/book-manage.component';
import { SearchInputComponent } from './searchbookcomponents/search-input/search-input.component';
import { BookListComponent } from './searchbookcomponents/book-list/book-list.component';

import { BookDetailComponent} from './searchbookcomponents/book-detail/book-detail.component';

import {NgZorroAntdModule} from 'ng-zorro-antd';
import { BookManageService } from './service/book-manage.service';
import { EffectsModule } from '@ngrx/effects';
import { BookManageEffects } from './effects/book-manager.effect';

@NgModule({
  imports: [
    CommonModule,
    NgZorroAntdModule,
    FormsModule,
    ReactiveFormsModule,
    StoreModule.forFeature('example', reducers), // This is the key,
    EffectsModule.forFeature([BookManageEffects])
  ],
  declarations: [CounterComponent, BookManageComponent,
    SearchInputComponent, BookListComponent, BookDetailComponent
  ],
  exports: [CounterComponent, BookManageComponent, BookListComponent, BookDetailComponent],
  providers: [BookManageService]
})
export class ExampleModule {}Copy the code

This. InjectorDefTypes:

A [[Entries]] :

Find the imports area under ExampleModule:

Code defined in the application code:

StoreModule.forFeature('example', reducers)
Copy the code

This method actually returns a module, StoreFeatureModule, which can be seen at runtime:



The Reducer for application authoring will also appear here:

The multilevel injector ModuleInjector and ElementInjector

This part of the article explains Angular dependency injection in detail

  • ModuleInjector: Configured through @NgModule() or @Injectable()
  • ElementInjector: Configured via the providers property of @Directive() or @Component()

ModuleInjector

  1. Injectable() ‘s providedIn property is requiredaboveProviders array of @NgModule()
  2. Optimization tools can do tree-shaking when using Injectable() ‘s providedIn property, such as providedIn:’ root ‘

For more of Jerry’s original articles, please follow the public account “Wang Zixi “: