简体   繁体   中英

Angular 4 access child of child component

I'm using ngx-charts line chart component which has a timeline inside. So the structure go like this : MyComponent -> LineChartComponent -> TimelineComponent.

(where LineChartComponent is the component from the library)

Having a reference to LineChartComponent is it possible to execute something like @ViewChild() on this reference to access the TimelineComponent ?

If it's projected, you can use @ContentChild() , otherwise you need LineChartComponent to make it available.

The better approach would be to use a shared service that you provide at MyComponent and inject to MyComponent and TimelineComponent and use like a message bus to communicate between these two components for example using Observables.

See also https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM