Assign component to a variable Angular 4+

Is it a valid typescript / Angular, or correct to assign a component to a variable? Just assigning , without type, etc.

For example:

import {CompB} from './comp-b.component';

export class CompA {
   let c = CompB; 


Or the right way will be to create an interface / use generic , etc?


2 answers

  • answered 2018-07-11 04:17 ngWolf

    I think you wan to communicate between components. If this is what you want then you should communicate using:

    1. Property Binding with Input and Output decorators
    2. A common service can be created to communicate and pass the data through this service.

    any of the ways will work.

    It's not good to use 1 component into another.

  • answered 2018-07-11 04:21 Sateesh

    You create Service/Interface to achieve same functionality you want. Using component into another component is not a good idea.

    You can communicate using service. For more information follow this URL: