Here is my service:
var MyService= function () {
var filters, charts, subscription;
return {
getFilters: function () {
return this.filters;
},
setFilters: function (value) {
this.filters = value;
},
getCharts: function () {
return this.charts;
},
setCharts: function (value) {
this.charts = value;
},
getSubscription: function () {
return this.subscription;
},
setSubscription: function (value) {
this.subscription = value;
}
};
};
angular.module('Something').factory('MyService', MyService);
Your typical service that can be used to pass arguments between controllers.
Controller A has a function that gets called when a user selects a link; the function sets my item in my service and uses window to redirect to another page.
$scope.pressedButton = function (subscription) {
MyService.setSubscription(subscription);
$window.location.href = 'newPage.html';
}
Controller B for the newPage.html should be able to read and console.log out myItem from my service however, it says it's undefined.
console.log(MyService.getSubscription()) == undefined.
Anyone know why? I've been using setters and getters but because I'm a bit limited to my routing ($window instead of ui-router or ng-router), I feel like moving to a brand new page is what's clearing out my service...
I believe you may have the syntax of factories and services swapped.
vs a service