I am currently refactoring my main controller in my small AngularJS application after reading about mocking server dependancies in JS and AngularJS apps.
In my markup I iterate over the "main events" using the ng-repeat directive:
This is my AngularJS module, refactored repository and controller.
However I am unable to access the main event array in this way - what am I missing?
// Module
var app = angular.module('MainEventApp', ['cloudinary']);
// Repository
app.service('MainEventRepository', ['$http', function($http) {
this.$http = $http;
this.getMainEvents = function() {
return [
{
id: 1,
roman_numeral: 'I',
name: 'Hulk Hogan & Mr T vs Rowdy Roddy Piper & Paul Orndorff',
venue: 'Madison Square Garden',
state: 'New York',
attendance: 19121
},
{
id: 2,
roman_numeral: 'II',
name: 'Hulk Hogan vs King Kong Bundy',
venue: 'Split-Transmission',
state: 'New York/Illinois/California',
attendance: 40085
}
];
};
}]);
// Controller
app.controller("MainEventCtrl", ['$scope', 'MainEventRepository', function ($scope, MainEventRepository) {
MainEventRepository.getMainEvents().then(function(main_events) {
//$scope.main_events = main_events;
return main_events;
});
}]);
My live application can be seen here (not yet refactored).