When passing a reference type value from the parent
to the child
, both components will work with the same value, allowing them to reflect all changes made to the reference value. Reference types can include not only an object
, but also an array
structure.
The question then arises: how does the parent
component know when to update the view to display these changes in the value? This issue can be resolved by the change detection system within Angular
.
If changes trigger an event in the parent
component, then there is no need to worry as the change detection system will handle everything automatically. If not, it is important to understand when to manually trigger the detectChanges
method of the ChangeDetectorRef
service within the parent
component. For instance, this can be achieved using the @Output
decorator in the child component, or by injecting the ChangeDetectorRef
with the option SkipSelf
into the child
and then triggering the detectChanges
method when object changes occur. There are numerous possibilities available to address this challenge.