007ruwan
007ruwan

Reputation: 124

Trigger event in Parent component from child component load in routing Angular

In my Angular 2 application, I have app.module and app.component app.component is my parent component and inside that, I have router-outlet to load pages based on my route. based on an event in one of my components load based on the route I want to trigger event in my app component. Is it possible and if so how to do it.

Upvotes: 0

Views: 2346

Answers (1)

Flow
Flow

Reputation: 580

yep you have to trigger an output event emiter in an ngOnInit in your child componant.

so in your child component you'll have

@Output() myEventOnInit= new EventEmitter<dataType>();
ngOnInit() {
    myEventOnInit.emit(myData)
}

then in your app.component template:

<my-child-componant (myEventOnInit)="myFunctionThatHanddleTHeInitComponant($event)"></my-child-componant>

myFunctionThatHanddleTHeInitComponant is a function you'll have to describe in your parent componant.

I hope it helped you and that i've understood your issue.

Upvotes: 2

Related Questions