I have three component-- Component A, Component B and Component C. Component A wraps Component B. Component B wraps Component C. If I use @Input() in each component, will changes to options in the root component pass through the nested components to Component C? See below:
<component-a [options]="options">
<component-b [options]="options">
<component-c [options]="options">
</component-c>
</component-b>
</component-a>
I asked this question because when options changes in the root component of the application I need to do some filtering at each nested component. However, I have noticed some unusual behavior with a third-party component that doesn't seem to receive options? I can elaborate further after the first part of this question is answered.
I believe the answer to the question is "Yes". So here is the second part. How do I update <ng-select> when the components are wraps as follows:
<component-a [options]="options">
<component-b [options]="options">
<ng-select [items]="options" [(ngModel)]="selectedOption">
</ng-select>
</component-b>
</component-a>
When the documentation for <ng-select> says the following:
Change Detection
Ng-select component implements OnPush change detection which means the dirty checking checks for immutable data types. That means if you do object mutations like:
this.items.push({id: 1, name: 'New item'})Component will not detect a change. Instead you need to do:
this.items = [...this.items, {id: 1, name: 'New item'}];This will cause the component to detect the change and update. Some might have concerns that this is a pricey operation, however, it is much more performant than running ngDoCheck and constantly diffing the array.
So how do I ensure changes to options is reflected in <ng-select>?