Issue
The API I am working with returns this if there are no items in the array
items: []
If there are items in the array it returns something like
items: [
{
name: 'Bla'
}
]
In my template I believe I need to use ng-if to either show/hide an element based on whether there is data in there or not.
<p ng-if="post.capabilities.items"><strong>Topics</strong>: <span ng-repeat="topic in post.capabilities.items">{{topic.name}}</p>
However I could be totally off base as this is my first time working in Angular, and there may be a much better way to do what I am trying to do.
Solution
post.capabilities.items
will still be defined because it's an empty array, if you check post.capabilities.items.length
it should work fine because 0
is falsy.
Answered By - Martijn Welker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.