0

For example:

First example with variable.

    ` <div id="loader" class="" *ngif="isLoader"></div>  ` 
    isLoader:boolean=false; 

    onLoad(){           
        isLoader=true;

        this.http.get('localhost/data').subscribe( 
             res=>{
               console.log(res.json());
               isLoader=false;   
             } 
        }
    }

Next example with set class on div

    ` <div id="loader" class=""></div>  `
    onLoad(){
         document.getElementById("loader").className = "loader";

         this.http.get('localhost/data').subscribe( 
            res=>{
               console.log(res.json());
               document.getElementById("loader").className = "";
            } 
         }
    }

Which example is better.

dragon
  • 13
  • 1
  • 6
  • In my opinion, the first option is more Angular 2 friendly and short to write. document.getElementById() is more javascript oriented than typescript. – mickdev Feb 27 '17 at 16:48
  • 2
    Thou shalt not use the DOM in components. Use binding. That's what Angular is all about. – JB Nizet Feb 27 '17 at 17:05
  • @JB Nizet - When use first exaple and have more elements to onLoad I will have a more variable have mess code. Can you do something about this. – dragon Feb 28 '17 at 11:30

0 Answers0