(function () { function appConfig($interpolateProvider, $httpProvider) { $interpolateProvider.startSymbol('{$'); $interpolateProvider.endSymbol('$}'); $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; } function Agenda($http) { let self = this; // Get the events from the endpoint let request = { method: 'GET', url: '/datos-agenda/' }; $http(request).then( function (response) { // response.data is a dict of the results so we access in the dict, key form self.countries = response.data['countries']; self.events = response.data['events']; // Select the first country of the dict, remember that the selected is a dict too // with the name of the country and the list of years self.selected_country = response.data['countries'][0]; self.selected_year = response.data['countries'][0]['years'][0]; //If there's no data response with message self.no_events = "No events" }, function (response) { } ); self.update_selected_country = function (country) { self.selected_country = country; // Change the selected year for the first year of the country because not all the // the countries have the same years self.selected_year = country['years'][0] }; self.update_selected_year = function (year) { self.selected_year = year; } } Agenda.$inject = ['$http']; angular.module('pinchef', []) .config(appConfig) .controller('AgendaController', Agenda) }());