From the tutorial, instructor came up with this:
<span class="glyphicon" [class.glyphicon-star-empty]="isFavorite" [class.glyphicon-star]="!isFavorite" (click)="toggleClass()"></span>
Component:
isFavorite = false;
toggleClass() {
this.isFavorite != this.isFavorite;
}
While my way was:
<span class="glyphicon" [ngClass]="classes" (click)="toggleClasses()"></span>
Component:
classes = "glyphicon-star-empty";
toggleClasses() {
this.classes == "glyphicon-star-empty"? this.classes = "glyphicon-star" : this.classes = "glyphicon-star-empty";
}
Both ways works as expected, but I feel my way is not very good from performance perspective because I am using a loop, right?
Sorry if answer might be simply "yes". I just want to be sure about how this works (especially interested in all those Ng directives, like ngModel, ngClass).
Thanks