How to implement conditional logic in AngularJS views

I have a controller with elements. Say I want to display items in a table if there are any items. How can such logic be implemented in a “view”?

+4
source share
2 answers

ng-repeat already takes care of it for you. ng-repeat only puts html there if there are elements.

Alternatively, if you don’t even want the table element to be there (don’t even confuse it with calculations!), You could do something like:

<table class="table" ng-show="items.length"> <tr ng-repeat="item in items"> <td>{{item}}</td> </tr> </table> 

Hope this helps.

+7
source

Check http://www.codinginsight.com/angularjs-if-else-statement/

Shameful expression angularjs if else !!! When I started using Angularjs, I was a little surprised that I could not find the if / else statement.

So, I was working on a project, and I noticed that when using the if / else statement, the condition is displayed at boot time. You can use ng-cloak to fix this.

 <div class="ng-cloak"> <p ng-show="statement">Show this line</span> <p ng-hide="statement">Show this line instead</span> </div> 

.ng-cloak {display: none}

Thanks amadou

0
source

All Articles