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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.