Angular2 providers in bootstrap vs @component

From my point of view, you can define your application providers in your bootstrap call as follows:

bootstrap(
  App,
  [disableDeprecatedForms(), provideForms()]]
)

or in your root component, for example:

@Component({
  selector: 'my-app',
  providers: [disableDeprecatedForms(), provideForms()],
  ...
)

However, I created a form validation plugin that required data providers, and this directive only works when configuring bootstrap parameters. I created plunk to glorify the problem : the validator works if I add providerForms () to the bootstrap call. As soon as I comment on providerForms () from the bootstrap call, the validator no longer works. I assumed that the definition of providerForms in the component was sufficient. Any explanation?

+4
1

Angular2 DI . , , , , .

bootstrap(...) @Component(...) , . bootstrap() .

Angular2 bootstrap(), .

(, V3, Router routerLink, ).

, , , bootstrap() .

+3

Source: https://habr.com/ru/post/1649714/


All Articles