Currently, I am in the process of creating a custom dropdown component. Within this component, I have a config object that is initialized within the ngOnInit()
method. This config object combines both default configurations as well as user-provided configurations through an @Input()
. However, upon making changes to the config object from the parent component at runtime, I noticed that these updates are not reflected in the ngOnChanges()
method of my child component.
In an attempt to resolve this issue, I have made adjustments:
Child Component
@Input() config: MyConfig;
@Input() disabled: boolean
ngOnChanges() {
console.log('config', this.config); // this is not updating
console.log('disabled', this.disabled); // this is being detected
}
Parent Component HTML
<button (click)="changeConfig()">Change Config</button>
<app-child [config]="customConfig" [disabled]="newDisabled"></app-child>
Parent Component TypeScript
newDisabled = false;
customConfig = {
value: 'code',
label: 'name',
floatLabel: 'Select'
};
changeConfig() {
this.customConfig.value = 'name';
this.newDisabled = true;
}
The state change works for the disabled variable, however, it does not apply to the config. Is there something I am missing or doing incorrectly? Any assistance would be greatly appreciated.