Skip to content Skip to sidebar Skip to footer

AngularJS Ng-repeat Doesn't Work If There Is Only One Element

Here is the html code:

Solution 1:

As said in the comments, ng-repeat the way you have is for an array. Use the following syntax for objects and properties:

(k, v) in cmsData.rss.channel.item

This will iterate each key/val pair inside cmsData.rss.channel.item


Solution 2:

The reason is because in the JSON object, the "item", isn't an Array.

To fix:

{
"rss": 
{
    "channel": 
    {
        "description": "",
        "item": 
        [{
            "description": "blah blah blah",
            "link": "http://foo.bar",
            "pubDate": "Friday, February 21, 2014 - 17:52",
            "title": "Server Maintenance"
        }],
        "language": "en",
        "link": "http://foo.bar/alerts",
        "title": "<a href=&#039;/news&#039;>News & Updates<\/a>"
    },
}}  

Solution 3:

You are referencing an object not an array, check the docs for using an object in ngRepeat's arguments.

http://docs.angularjs.org/api/ng/directive/ngRepeat

You would need data-ng-repeat="(key, value) in cmsData.rss.channel.item

Then you could use <div data-ng-bind-html="value"></div> which would list all of item's properties.


Post a Comment for "AngularJS Ng-repeat Doesn't Work If There Is Only One Element"