I am trying to store JSON's data in a shared array within a service. The problem is that every time I want to update the service's array with some new content (e.g. new JSON), I need to first clear the array and after that the array remains empty, instead of loading new data.
My service looks like this:
.service('jsonTest',
function() {
var json = [];
function storeJson(file) {
json=[];
json.push(file);
}
return {
storeJson: storeJson,
showJson: json
}
});
As you can see, I am cleaning the array each time before loading new data with
json = [];
But then it still remains empty after loading new stuff.
What am I doing wrong here?
You can check that example here: http://plnkr.co/edit/tN9WvNminw1uLpThWPvu?p=preview The service is in app.js and is being used in MainCtrl (main.js) and ProductCtrl (product.js).
Any advice please?