I've looked high and low for an answer to this, but nothing that directly addresses this. The issue is this -- I have a function that gets a list of calendars from an endpoint. I have another function that counts the number of events for each calendar. I have it creating a dynamic variable every time it's called in the ng-repeat list, attaching the calendar ID to the word "count" as the variable name.
function getEventsCount(calendarId) {
if(calendarId !== '') {
calendarService.getCalendarEvents(calendarId, fromDate, toDate).then(function (result) {
if(isSuccessResponse(result)) {
$scope['count' + calendarId] = result.events.length;
} else {
$scope.errorMessage = errorText + result.errorMessage;
}
});
}
}
In the HTML I want to display the numerical count of events for each calendar, but since we're iterating through an ng-repeat list which will return any given number of calendar IDs, I don't know what the variable name for count will be, so I need angular to somehow parse the variable name inside of those braces for the value.
<ul class="list-group">
<li class="list-group-item" data-ng-repeat="calendar in calendarList.calendars" data-ng-init="getEventsCount(calendar.id)">
<a roll="button" class="btn-link" data-ng-click="showCalendar(calendar.id, calendar.summary)">{{calendar.summary}} ({{count + calendar.id}})</a>
</li>
</ul>
Forgive me if the question is muddy, I'll be happy to clarify if needed.
countproperty to yourcalenderobject and just use that instead of some complex scope dictionary?