To listen to the eventEmitted , all you have to do is :
<child-component (parentEvent)='postMethod1($event)'></child-component>
Now everytime an event is emitted by child component , postMethod1()
is called and the data sent will be passed as parameter to the method .
EDIT
Since you want to handle the exception , you can use a shared service to notify the child component .
Suppose you have a shared.service.ts
In shared.service.ts
,you can do something like this :
exception : Subject<String> = new Subject<String>();
now you can create a method to send an exception from parent to child :
exceptionRaised(parentException : any){
this.exception.next(parentException);
}
With this method , the exception can be subscribed in the child component like this :
in child.component.ts
_sharedService.exception.subscribe((exception : any) =>{
//do whatever you want with the exception
});
To set the exception in parent ,
in parent.component.ts
just call _sharedService.exceptionRaised(yourException);
Now your parent can communicate with child and notify if you have an exception