Last active
December 26, 2019 14:43
-
-
Save Verthon/96b396e95e31f122092defa9654958d9 to your computer and use it in GitHub Desktop.
Select ion-chip tags
This file contains 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
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