I'm currently working on creating an array in my application that is universally accessible through services. Additionally, I have implemented ui-router in my application. In the app.js file, I define the service like this:
myFamilyApp.service('global', function() {
var eventArray = [];
return {
addEvent: function() {
eventArray.push(newObj);
}
}
});
After defining the service, I try to call it from my controller:
myFamilyApp.controller('newEventController', [ '$scope', '$state',
function($scope, $state, global) {
eventConfig = {//variables to create event};
e = new Event(eventConfig);
global.addEvent(e);
});
However, I encounter an error message stating:
TypeError: Cannot read property 'addEvent' of undefined
The issue seems to be that the controller cannot recognize the global variable, but I am unsure why. Despite trying various approaches and looking at different resources, I still can't figure out how to make my controllers access the service properly. Any insights or suggestions would be greatly appreciated.