Angular for Loop is slow and solution
Slow code:
for (var i = 0; i < this.PayLinkMoreList.length; i++) {
this.PayLinkMoreList[i].showEmailNormalE = true;
this.PayLinkMoreList[i].showEmailNormalS = true;
this.PayLinkMoreList[i].showEmailStar = true;
this.PayLinkMoreList[i].showSmsStar = true;
}
Slow code2:
(this.PayLinkMoreList).forEach(key => {
let k: any = key;
//debugger
k.showEmailNormalE = false;
k.showEmailNormalS = false;
k.showEmailStar = false;
k.showSmsStar = false;
})
Solution:
Share on Facebookthis.PayLinkMoreList.map((todo, i) => {
if (todo.showEmailStar == false) {
todo.showEmailStar = true;
} else {
todo.showEmailStar = false;
}
});
this.PayLinkMoreList.map((todo, i) => {
if (todo.showSmsStar == false) {
todo.showSmsStar = true;
} else {
todo.showSmsStar = true;
}
});
Page views:682