HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
Angular for Loop is slow and solution

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:

 this.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;
      }
    });

   Share on Facebook

Page views:1175