0

I have five pages with different state. The first page contains object with the format

{
  "good": {
    "good1": "good",
    "good2": "good",
    "good3": "good"
  },
  "bad": {
    "bad1": "bad",
    "bad2": "bad",
    "bad3": "bad"
  },
  "excellent": {
    "excellent1": "excellent",
    "excellent2": "excellent",
    "excellent3": "excellent"
  }
}

this object is saved to localstorage. This is my codepen where i have tried to show what i really want.The scenario is , good1 value is going to be looping through 4 pages and next time redirect to first page with the next value(ie good2 ) and the next value also goes through the same 4 pages and so on. What i have to do to solve this problem? if i am doing wrong with the object structure, what should be the good approach?

1 Answer 1

2

I would recommend that you put your data into a service, then it will be much easier to share it between pages, persist it to local storage and retrieve it.

.factory('amazingData',function() {
  var ohYeah = {
    'good':{
      'good1':'good',
      'good2':'good',
      'good3':'good'
    },
    'bad':{
      'bad1':'bad',
      'bad2':'bad',
      'bad3':'bad'
    },
    'excellent':{
      'excellent1':'excellent',
      'excellent2':'excellent',
      'excellent':'excellent'
    }
  };

  return ohYeah;
})

Now you can use this service and inject it into your controllers:

.controller('homeCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})
.controller('pageCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})

The data will be the same for all pages.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.