The first page is where i select the data. When i click the button that runs the function on that page, it then sends the data to a service, and on the second page, that controller pulls the data from the service and displays it.
The problem I am having, is if i go back to the first page, change the value, and click the button that runs the function, the data on the second page displays the first value, and not the updated value.
Service Code:
app.service('popService', function(){
var popData = [];
var addData = function(newObj){
popData.push(newObj);
};
var getData = function(){
return popData[0];
};
return{
addData: addData,
getData: getData
};
});
Code for passing data to the service in the first controller:
$scope.passData = function(){
$total_value = $(".total").html();
$scope.someData = $total_value;
popService.addData($scope.someData);
};
Code for retrieving data in the second controller:
$scope.totals = popService.getData();
Im still not getting it. Sorry. Let me try to re-explain.
I have lets say, 10 variables that I need to store, on different pages. From what I have understood so far, 1 service that stores all of these variables in an array would be best. (i currently have like 6 services, storing different variables, so i can target them).
My new question is, how do i store multiple variables to 1 var in the service, and then how do i target them with getdata? example:
app.service('example_service', function(){
var storedData = [];
var addData = function(newObj){
storedData.push(newObj)
};
var getData = function(){
return storedData;
};
return {
addData: addData,
getData: getData};
});
.
And for passing data to it:
$scope.passData = function(){
$scope.data_1 = 1;
$scope.data_2 = 2;
$scope.data_3 = 3;
popService.addData($scope.data_1);
popService.addData($scope.data_2);
popService.addData($scope.data_3);
};
So lets say I push 3 items, and i want to clear the second. Something like storedData[1].length = 0;?
Apologies if this is cryptic, im trying my best to explain what I need, and where im failing to get it.
And then when i goto grab one of those 3 items in the array:
$scope.data_1 = popService.getData(); (how do i target a specific item?)