Search code examples
javascriptangularjsangularjs-ng-repeathybrid-mobile-app

Why isn't my ng-repeat working?


I've tempted to do an ng-repeat that will retrieve card titles and place them into a list. Here is a section from my code that calls the content:

<ion-content class="has-header" scroll="false" ng-controller="MainCtrl">
    <div id="accordian">
      <ul>
        <li>
          <h3><span class="icon-dashboard" ng-repeat="card in cards"></span>Group 1</h3>
          <ul>
            <li><a href="#">{{ card.title }}</a></li>
          </ul>
        </li>

Here is the controller:

    .controller('MainCtrl', function($scope,$http) {

// Card Array
$scope.data = {};
$scope.cards =[
{checked: false, title:'Bank', src:'img/bank.png',details:'Description will go here!'},
{checked: false, title:'BBVA', src:'img/bbva.png',details:'Description will go here!'},
{checked: false, title:'Nike', src:'img/nike.png',details:'Description will go here!'},
];

Solution

  • Your current code will repeat the span tag for each card that you have inside cards. I don't think that's what you intended to do. You probably want to repeat the li, right? Try this instead:

        <li ng-repeat="card in cards">
          <h3><span class="icon-dashboard"></span>Group 1</h3>
          <ul>
            <li><a href="#">{{ card.title }}</a></li>
          </ul>
        </li>