AngularDart 5: How to get parent component


In AngularDart 3 or 4, we can write

    selector: 'my-app', 
    template: '<my-child></my-child>', 
    directives: [ChildComponent])
class AppComponent {}

@Component(selector: 'my-child', template: 'The child')
class ChildComponent {
  final AppComponent _parent;


The ChildComponent has the parent injected in the constructor.

When I try to convert this code to AngularDart 5, I have this error:
No provider found for AppComponent

What is the correct way to convert this code to AngularDart 5?


You need to set the visibility of the parent to make it injectable

  visibility:  Visibility.all

or (see also

  selector: 'parent',
  directives: const [Child],
  providers: const [
    const ExistingProvider(Example, useExisting: Parent),

This change was made to reduce generated code size.

Answered By – Günter Zöchbauer

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *