Open giovannidias1 opened 4 years ago
After some time I discovered that the problem is in the way the inputs are read because one is called after the other
A workaround to fix the problem was this:
public set data(value: Array<any>) {
setTimeout(() => { // <--- add this timeout
if (!value) {
this._data = [];
} else {
const firstItem = value[0];
this._sourceDataType = typeof firstItem;
this._sourceDataFields = this.getFields(firstItem);
this._data = value.map((item: any) =>
typeof item === 'string' || typeof item === 'number'
? new ListItem(item)
: new ListItem({
id: item[this._settings.idField],
text: item[this._settings.textField],
isDisabled: item[this._settings.disabledField]
})
);
}
}, 1);
}
Same problem here...
@Michi-2142 there is an issue #216. AndrewTaftPlusone solved the problem by moving settings param prior to the data param.
import {IDropdownSettings} from 'ng-multiselect-dropdown'; const reports$ = new Observable(observer => { setTimeout(() => { const reports = [ { name: 'displayName', type: 'key' }, { name: 'displayName', type: 'key' }]
observer.next(reports);
observer.complete();
}, 1000);
});
reports$.subscribe((data) => {
console.log('data', data)
this.reports = data;
})
}
<ng-multiselect-dropdown tabindex="0" (onDeSelect)="unselectType($event)"
(onSelect)="onTypeSelect($event)" [(ngModel)]="selectedType"
[data]="reports"
[placeholder]="'Custom placeholder'" [settings]="dropdownSettingsReportType">
</ng-multiselect-dropdown>
It's working in Angular 9.0.1 Thanks : https://stackblitz.com/edit/angular-vkrvjz?file=src%2Fapp%2Fapp.component.ts
@Michi-2142 there is an issue #216. AndrewTaftPlusone solved the problem by moving settings param prior to the data param.
This worked for me, too. Thank you!
Also #207 seems to be the same issue.
I don't think it's necessary to resort to a setTimeout(). ~~That data mapping code should be split out into a separate function and given the appropriate checks to make sure data & settings are both set before trying to use their values. Then that function would be called from the settings setter function as well as the data setter function.~~
Actually that struck out idea won't work, unless the component is also storing the unmodified input data, which is not the current intent.
One solution would be to move to using ngOnChanges instead of setters, that way you will get the values of data and settings at the same time.
Angular version:
ng-multiselect-dropdown version: ng-multiselect-dropdown@0.2.10
Description of issue: After updating angular 9 and the latest version of multi-select some of the mult-selects used stopped working not listing the items. The problem is occurring when using ng if to show a select or when the date is a static variable making the date observable with a timeout works
Steps to reproduce:
Expected result:
Actual result:
Demo: Stackblitz running angular 8 https://stackblitz.com/edit/angular-vkrvjz
Not working code
working code