My task seems simple, but it required some contemplation. I need to create an empty array even when the parent component sends null. There's an input element in my code that expects an array[] from the parent, but sometimes the parent sends null instead of an empty array, causing issues. Here is a snippet of my code:
/* child component */
@Input() selectedIds: GenericID[];
<!--Parent HTML-->
<sample-listbox
id="dataIds"
[(selectedIds)]="dataIds"
inputType="number">
</sample-listbox>
I attempted to modify the child component to handle the input data differently, but the changes are not reflecting in the parent component. I tried using 'set' and 'get' keywords, but it seems to be unidirectional.
NOTE: Modifying the data sent from the parent component is not an option for me.
/* Edited Child component */
selectedIds: GenericID[];
@Input('selectedIds')
set selectedIdss(value: GenericID[]) {
if (value) {
this.selectedIds = value;
}else {
this.selectedIds = [];
}
}
get selectedIdss() {
return this.selectedIds;
}