Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private setSelectionByValue(value: any | any[]): void {
if (this.multiple && value) {
if (!Array.isArray(value)) {
throw getMcSelectNonArrayValueError();
}
this.selectionModel.clear();
value.forEach((currentValue: any) => this.selectValue(currentValue));
this.sortValues();
} else {
this.selectionModel.clear();
const correspondingOption = this.selectValue(value);
// Shift focus to the active item. Note that we shouldn't do this in multiple
// mode, because we don't know what option the user interacted with last.
if (correspondingOption) {
this.keyManager.setActiveItem(correspondingOption);
}
}
private setSelectionByValue(value: any | any[]): void {
this.previousSelectionModelSelected = this.selectionModel.selected;
if (this.multiple && value) {
if (!Array.isArray(value)) {
throw getMcSelectNonArrayValueError();
}
this.selectionModel.clear();
value.forEach((currentValue: any) => this.selectValue(currentValue));
this.sortValues();
} else {
this.selectionModel.clear();
const correspondingOption = this.selectValue(value);
// Shift focus to the active item. Note that we shouldn't do this in multiple
// mode, because we don't know what option the user interacted with last.
if (correspondingOption) {
this.keyManager.setActiveItem(correspondingOption);
}
}
private setSelectionByValue(value: any | any[]) {
if (this.multiple && value) {
if (!Array.isArray(value)) { throw getMcSelectNonArrayValueError(); }
this.selectionModel.clear();
value.forEach((currentValue: any) => this.selectValue(currentValue));
this.sortValues();
} else {
this.selectionModel.clear();
const correspondingOption = this.selectValue(value);
// Shift focus to the active item. Note that we shouldn't do this in multiple
// mode, because we don't know what option the user interacted with last.
if (correspondingOption) {
this.tree.keyManager.setActiveItem(correspondingOption);
}
}
this.changeDetectorRef.markForCheck();
private setSelectionByValue(value: any | any[]) {
if (this.multiple && value) {
if (!Array.isArray(value)) { throw getMcSelectNonArrayValueError(); }
this.tree.setOptionsFromValues(value);
this.sortValues();
} else {
this.tree.setOptionsFromValues([value]);
}
this.changeDetectorRef.detectChanges();
}
writeValue(value: any): void {
if (this.multiple && value && !Array.isArray(value)) {
throw getMcSelectNonArrayValueError();
}
if (this.renderedOptions) {
this.setOptionsFromValues(this.multiple ? value : [value]);
}
}