пользователей: 30398
предметов: 12406
вопросов: 234839
Конспект-online
РЕГИСТРАЦИЯ ЭКСКУРСИЯ

I семестр:
» Angular
» Git

Modules

@NgModule({

declarations: [components, directives, pipes],

imports: [modules],

providers: [service providers],

entryComponents: [components],

exports: [modules, components, directives, pipes],

bootstrap: [AppComponent]

}) 

takes a metadata object that describes how to

  1. compile a component's template
  2. create an injector at runtime

declarations

  • declarables are componentsdirectives and pipes
  • declarables must belong to exactly one module
  • these declared classes are visible only within the module

providers

  • you list services here, they are available app-wide
  • provider is an instruction to the DI system on how to obtain a value for a dependency
  • most of the time, these dependencies are services that you create and provide
  • when the Angular router lazy-loads a module, it creates a new injector (child)

bootstrap

  • you can put more than one component
  • these components are automaticaly added to entryComponents

entryComponents

  • loads imperatively, (which means you’re not referencing it in the template), by type
  • bootstrap and routed components are entryComponents automatically
  • if a component isn't an entry component and isn't found in a template, the tree shaker will throw it away

A component can also be bootstrapped imperatively:

import { NgModule, ApplicationRef, DoBootstrap } from '@angular/core';
 
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
entryComponents: [ AppComponent ]
})
export class AppModule implements DoBootstrap {
ngDoBootstrap(appRef: ApplicationRef) {
appRef.bootstrap(AppComponent);
}
}

Feature modules

  1. Domain feature modules (dedicated to a particular application domain like editing a customer)
  2. Routed feature modules (whose top components are the targets of router navigation routes)
  3. Routing modules (defines routes, adds guard and resolver service providers to the module's providers)
  4. Service feature modules (they consist entirely of providers(like HttpClientModule). The root AppModule is the only module that should import service modules)
  5. Widget feature modules (a widget module makes components, directives, and pipes available to external modules)

 


09.06.2019; 17:23
хиты: 115
рейтинг:+1
Точные науки
информатика
Языки программирования
для добавления комментариев необходимо авторизироваться.
  Copyright © 2013-2024. All Rights Reserved. помощь