Skip to content

Instantly share code, notes, and snippets.

@thisiszoaib
Created January 5, 2021 05:11
Show Gist options
  • Save thisiszoaib/277ed0140611ce9c7d54ea3cb01afd57 to your computer and use it in GitHub Desktop.
Save thisiszoaib/277ed0140611ce9c7d54ea3cb01afd57 to your computer and use it in GitHub Desktop.
Chips 7
@ViewChild(MatChipList) chipList!: MatChipList;
value: string[] = [];
writeValue(value: string[]): void {
// When form value set when chips list initialized
if (this.chipList && value) {
this.selectChips(value);
} else if (value) {
// When chips not initialized
this.value = value;
}
}
selectChips(value: string[]) {
this.chipList.chips.forEach((chip) => chip.deselect());
const chipsToSelect = this.chipList.chips.filter((c) =>
value.includes(c.value)
);
chipsToSelect.forEach((chip) => chip.select());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment