Created
January 5, 2021 05:11
-
-
Save thisiszoaib/277ed0140611ce9c7d54ea3cb01afd57 to your computer and use it in GitHub Desktop.
Chips 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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