Acceda a un método de componente desde otro componente en Angular 4
Tengo un componente de tablero, un componente de cabecera y un componente de descripción general del usuario.
dashboard component .ts file
export class DashboardComponent implements OnInit {
startTour() {
// do something
}
}
userOverview componente .ts file
export class UserOverviewComponent implements OnInit {
startTour() {
// do something else
}
}
header component .html file
<button (click)="openTour()"></button>
header component .ts file
export class HeaderComponent implements OnInit {
openTour() {
// In here, I want to ask is there any way I could make a
// call to different component with the same method same.
this.name = componentName // The component Name, such as
// DashboardComponent, UserOverviewComponent
this.name.startTour(); // Something like this
}
}
Ahora puedo obtener this.name cuando navego a un componente diferente, pero sé que usar this.name.startTour () definitivamente no va a funcionar.
Gracias por cualquier sugerencia o solución.