How to access a component from different module in angular 2

Pragmatic picture Pragmatic · Nov 2, 2016 · Viewed 10.1k times · Source

I am new to angular 2, so please excuse me if this question sounds trivial to you. I am creating a feature module in angular 2 and I will export all the components from this module. Main module can import it and add this module in import list. By doing so, all the "template" in main module can access feature module's component.

But what I want is: in one of the my main module's component, I want to refer feature module's component as ViewChild.

Answer

Günter Zöchbauer picture Günter Zöchbauer · Nov 2, 2016

You need to import the component class with a TypeScript import like

import {MyComponent} from './my.component'

then you can use it in @ViewChild()

@ViewChild(MyComponent) myComponent:MyComponent;