4

I have a controller with items. Let's say I want to display items in a table if there are any items. How can such logic be implemented in a "view"?

2 Answers 2

7

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

Alternately, if you dont even want the table element to be there ( not even mess 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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

The infamous angularjs if else statement!!! When I started using Angularjs, I was a bit surprised that I couldn’t find an if/else statement.

So I was working on a project and I noticed that when using the if/else statement, the condition shows while loading. 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.