What is the best to handle reference type data, for example json data, bind to a component. For example,
<my-component [data]="jsonData"></my-component>
where in .ts jsonData= {'key1':'value1','key2','value2'}
Now if on button click I change my jsonData as
{'key1':'valueX','key2','value2'}
Angular won't be able to detect this change, hence doesn't run ngOnChanges(),because angular only checks reference of the data-binding changed or not as a result view won't be refreshed. How should I deal with it?
I can put logic to refresh my view in ngDoCheck() but it is called a lot of times. If json is large, then processing it each time ngDoCheck runs can be an expensive operation.
One possible solution I could think of is to make a service for that component, and on button click, pass the new json to that service, service will publish that event with changed data to my component and component, listening for the events of service, will refresh the view with that new data.
Is there any easier way to handle JSON/Array changes bind to component?