Friday, January 5, 2018

Talk up to a wrapping component from a nested component in an Angular 4 app and not just down to the nested component from the wrapping component.

How is this possible? Just change values on the object being handed down. The wrapping component and the nested component are going to be using the same reference. You may then have logic in your wrapping component check against state changes in the object being handed in as an Input to the nested component. This provides a way to speak back up without an EventEmitter. Is it the most elegant thing to do? Maybe not. This will not trigger ngOnChanges at the wrapper so if you need an immediate reaction you will still need to use an EventEmitter. If you merely need to react when a user clicks something or something like that however, this will work for you. You may doublecheck state at that time.

No comments:

Post a Comment