How to call router outlet child component method from parent comonent


Solution 1

There are basically two ways to display a component's template: As a nested component or as a routing target.

Nested Component

If you use a nested component, then the components are considered to have a "parent component/child component" relationship.

The Html for the parent component would then look like this:


Where "child" is the selector of the child component. You can then communicate between the two using @Input and @Output properties.

For more information on this technique when you have nested components, check out the docs here:

Routing Target

If you use a component as a routing target by displaying it in a <router-outlet>, then there is no "parent component" and "child component" relationship.

The best way to communicate between components in this case is to use a service.

I have a blog post about creating a service here:


If you are new to Angular, you may save your self a bunch of time and frustration by working through a tutorial or online course. That will introduce all of the basic concepts to get you on your way with Angular quickly.

You can work through the "Tour of Heroes" tutorial here:

Or watch a course such as this one:

Or this one:

(You can sign up for a free week.)

Solution 2

With child in router-outlet, you can use ContentChild to be able to call a method in the child. So...

import { ContentChild } from '@angular/core';

in your parent:

private childComponent: ChildComponent;

and on your click event do:


Also you need to add your child component in the providers array in parent:

  selector: 'parent',
  providers: [ChildComponent]

Solution 3

I found two ways to achieve this:

1. Injecting the main component into children

You can add an event to your main component, inject the main component to your child components and subscribe to the event. See the plunk that illustrates this. But, now your children have a dependency on your main component. This may be not good.

main component

executeAction: EventEmitter<any> = new EventEmitter();
constructor() { }
performAction() {


constructor(private appComponent: AppComponent) {
    this.executeAction = this.executeAction.bind(this);
    eventSubscriber(appComponent.executeAction, this.executeAction);
ngOnDestroy(): void {
    eventSubscriber(this.appComponent.executeAction, this.executeAction, true);
executeAction() {

2. Implementing a service

The best solution here and as described in Parent and children communicate via a service is to create a service that will be an additional layer between the main component and children. In this way, you will be independent from the main component implementation. See the plunk that illustrates this approach.


subscription = new Subject();
executeAction() {;

main component

constructor(private appService: AppService) { }
performAction() {


constructor(private appService: AppService) {
    this.executeAction = this.executeAction.bind(this);
    eventSubscriber(appService.subscription, this.executeAction);
ngOnDestroy(): void {
    eventSubscriber(this.appService.subscription, this.executeAction, true);
executeAction() {

Solution 4

I think Event emitter can do the trick for you

Though you can use it directly in child component also but using a common service here would be a good practice

First you need to create an emitter in a service something like

export class EmitterService {
   public nameEmitter:EventEmitter<string>=new EventEmitter(); 

    //method to get question


Then in root component inject service dependency and call change name method to emit the change

 constructor(private emitter :EmitterService) {}
 this.emitter.changeName("New Name");

And at the end in child component subscribe to changes


Here is working plunker

Solution 5

You can use a shared service to communicate with components added by the router.

You can also use the activate event of the Router outlet for the parent to know when a component was added by the router


<router-outlet (activate)="onActivate($event)"></router-outlet>



Child Comp

Author by


Experienced Software Engineer with a demonstrated history of working in the Information Technology Industry. Skilled in Java,Angular and Web Applications Development. An Engineering Professional with a B.Tech major in Computer Science.

Updated on June 17, 2022


    LMK IND over 1 year

    I am new to angular2


    I have a button in parent component, if I click that button it should call a method in the child component (which is loaded in router outlet.)

    Is there any way to call the child component (in router outlet) method from parent ?