byrdr
byrdr

Reputation: 5487

Angular displaying data from within JSON array

I can't seem to figure out what I'm doing wrong here. I'd like to drill down into the JSON array below to display data from within the months array.

My schema:

var mongoose  = require('mongoose');
var Schema    = mongoose.Schema;

var CalendarSchema   = new Schema({

August: [
  {
    day: String,
    title: String,
    summary: String,
    description: String
  }
      ]
});

var Calendar = mongoose.model('CalendarData', CalendarSchema);



Calendar.find({}).exec(function(err, collection){
  if(collection.length === 0){
  Calendar.create({
'August': [
    {
      'day':'21', 
      'title':'cal title', 
      'summary': 'calsummary', 
      'decription': 'cal desc'
    }
          ]
    });
  }
});


module.exports = mongoose.model('CalendarData',  CalendarSchema);

my angular controller

 $scope.calendar = [];

 CAL.API.query(function(results) {
        $scope.calendar = results;
    }); 

My view

<div class="events" ng-repeat="cal in calendar.August">
   <h5>{{cal.title}}</h5>
</div>

JSON object coming through to controller

[
  -{
    _id: "53cfb6616ba190954d7682aa"
    __v: 0
    -August: [
         -{
          day: "21"
          title: "cal title"
          summary: "calsummary"
          _id: "53cfb6616ba190954d7682ab"
          }
            ]
    }
]

Upvotes: 0

Views: 677

Answers (1)

Anthony Chu
Anthony Chu

Reputation: 37540

August is an array inside of an array You should iterate over it in ng-repeat...

<div class="events" ng-repeat="event in calendar[0].August">
   <h5>{{event.title}}</h5>
</div>

Upvotes: 2

Related Questions