Skip to content

Instantly share code, notes, and snippets.

@Verthon
Last active December 26, 2019 14:43
Show Gist options
  • Save Verthon/96b396e95e31f122092defa9654958d9 to your computer and use it in GitHub Desktop.
Save Verthon/96b396e95e31f122092defa9654958d9 to your computer and use it in GitHub Desktop.
Select ion-chip tags
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.information = navParams.data.data;
this.children = [{ id: 1, name: 'Ginny Weasley' }, { id: 2, name: 'Harry Potter' }, { id: 3, name: 'Ronald Weasley' }, { id: 4, name: 'Luna Lovegood' }];
this.selectButtonText = 'SELECT ALL';
this.tagDefaultColor = "secondary";
this.quantity = 0.0;
this.bottleNote = "";
this.bottleDate = new Date().toISOString()
this.shareWithFamily = true;
this.bottleDefaultTime = moment().format('hh:mm a');
this.selectedChildren = [];
}
selectAll() {
if (this.selectButtonText === 'SELECT ALL') {
this.selectButtonText = 'UNSELECT ALL'
this.tagDefaultColor = "primary";
this.selectedChildren = [...this.children];
} else {
this.selectButtonText = 'SELECT ALL'
this.tagDefaultColor = "secondary"
this.selectedChildren = [];
}
}
changeTagColor(chip, i) {
console.log(chip.firstElementChild.innerText)
if (chip.color === "secondary") {
chip.color = "primary"
} else {
chip.color = "secondary"
}
}
// html part
<button ion-button full color="primary" class="select-all-btn" (click)="selectAll()">{{selectButtonText}}
<div class="students-tags">
<ion-chip [id]="child.id" #chip [color]="tagDefaultColor" (click)="changeTagColor(chip, i)" *ngFor="let child of children; let i = index">
<ion-label>{{child. name}}</ion-label>
</ion-chip>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment