angularjs - Angular 2 digest fails at executing a function, or finding a change at an object's property -
i have absolutely no idea on what's going on; 2 theories in title. thing is, should working, somehow 1 of core parts of angular, digest cycle, failing hard.
what want do, , how did it
a comments section instantiated in parent view, when click button. comments appear, , behave reddit's: can upvote or downvote them. pretty same! added arrows, , rating of comments between them:
<div class="rating"> <ion-row> <button class="nocolor" (click)="ratecomment(comment, true)"> <ion-icon large name="arrow-up" [color]="israted(comment.rated, 1)"></ion-icon> </button> </ion-row> <ion-row> <span [style.margin-left]="pointsmargin(comment.rating)">{{comment.rating}}</span> </ion-row> <ion-row> <button class="nocolor" (click)="ratecomment(comment, false)"> <ion-icon large name="arrow-down" [color]="israted(comment.rated, 2)"></ion-icon> </button> </ion-row> </div>
as can see, when click in icons, execute "ratecomment" function, is:
ratecomment(comment, liked){ if (liked==true){ comment.rating++; comment.rated=1; //register }else{ comment.rating--; comment.rated=-1; //register unlike } }
ok, pretty straightforward. object's property changed, should somehow change icon's color default gray-like color, more amber. works when data first represented: see voted comments proper arrow, proper colored. great. but if click in arrow, color doesn't change.
the function chooses color of icon, works @ start fails when updating view, one:
israted(value, component){ if(component == 1 && value == 1){ return 'amber'; }else if(component == 2 && value == -1){ return 'amber'; } }
basically, can see, upper arrow uses 1 component value , down arrow uses 2, reuse function.
so, what's problem?
as said, problem i'm having here, either "israted" function not being executed in digest's cycle, or change os ion-icon color not working, or property change of object not trigger view update. don't know what's going on; failing hard , can't find error in code.
edit: "israted" function executed, old value, if new 1 doens't registered in object. odd, since gets changed in "ratecomment" function.
Comments
Post a Comment