Follow by Email

AngularJS Conditions and loops

AngularJS  -  Conditions :

In AngularJs if conditions can be handled using ng-if directive. 
why ng-if ?
The ng-if directive will bind the html element in the DOM only if the condition is true.
If the if statement is false then the element will not be added to the DOM. It is preferred then ng-hide/ng-show which will bind the element to the DOM even if the condition is false or true.


Below is the DOM binding in the html for the above example :


AngularJS  -  loop:

In AngularJs for loop can be handled using ng-repeat directive.

Definition  : ng-repeat 

The ng-repeat directive will apply foreach loop in the html.
It is used repeat a similar set of data in repeated elements, for ex: table <table> having repeated <tr><td></td></tr>