Search code examples
angulardependency-injectionangular-dart

AngularDart: how to add providers/directives to sub-components in one time


I got the following error when I tried to bind a String to ngModel:

Error: Template parse errors: line 2, column 21 of ChatFormComponent: ParseErrorLevel.FATAL: Can't bind to 'ngModel' since it isn't a known native property or known directive. Please fix typo or add to directives list. [(ngModel)]="message"

This error is because it is missing formsDirectives in the component: https://webdev.dartlang.org/angular/tutorial/toh-pt1#declare-non-core-directives

It worked after I added it. However, I am tired of adding directives one by one to every components. I have two questions:

  1. Does anything like AppModule exist in angularDart? So that all the provider/directives registered in AppModule works for every sub-components. If it exists, is it suggested to use?
  2. Are there any other quick ways to add providers/directives one time to all the sub-components?

Thank you


Solution

  • You need to add providers to each component. There is no way around it.