8

I have an application which contains three components. Application, EditView,Dialog.

Application components contains EditView components which can contain many other EditView components and one Dialog component( if Dialog component is visible on a page).

Dialog component contains Application component. When I put that in Dialog component in declaration path:

directives:[Application]

I'am getting this error:

Unexpected directive value 'undefined' on the View of component 'Dialog'

Is it possible at all to have such structure where child component can contain component from upper level regarding some conditions?

If I drop Application component from Dialog or replace it with other components it works fine.

Zlaja

zlaja
  • 1,351
  • 3
  • 13
  • 23
  • This is discussion from Google Angular group: https://groups.google.com/forum/#!topic/angular/tDU5sw1vBwc – zlaja Sep 21 '15 at 10:17

2 Answers2

4

Putting it in the directives list won't work, but you can still have access to the parent component by having it injected in the constructor of the child directive:

constructor(@Host(Application) application: Application) {

}

And the parent component can get a live list of child components using @Query:

constructor(@Query(EditView) editViews: QueryList<EditView>){

}
Angular University
  • 42,341
  • 15
  • 74
  • 81
  • Justo to clerify. I want to have new Application instance in Dialog component. Application -> EditView -> Dialog -> Application( this is new instance). – zlaja Sep 22 '15 at 20:48
  • With forwardRef I've managed Dialog component can see Application component in directives, i checked it in debug mode. Now, I'am getting this error: Unconditional component cycle in Application. See https://groups.google.com/forum/#!topic/angular/tDU5sw1vBwc. – zlaja Sep 24 '15 at 09:33
0

I've solved problem using DynamicComponentLoader.

See https://groups.google.com/forum/#!topic/angular/tDU5sw1vBwc

zlaja
  • 1,351
  • 3
  • 13
  • 23