AngularJS $scope data across different pages
-
21-12-2019 - |
Question
I'm getting to grips with AngularJS and I am working on an application just now where I have questions and answers.
The questions use an incrementing +
and -
button per item which updates the $scope
What I am wondering though, because I will have to access the values from the question side of the app in the answers, what would be the simplest way to get this across. I had thought of storing the $scope.questions into localstorage.
{
"uid" : 1,
"name": "Quiz",
"drinks" : [
{
"id" : 0,
"type" : "Footballs",
"image" : "http://placehold.it/280x300",
"amount" : ""
},
{
"id" : 1,
"type" : "Golf Balls",
"image" : "http://placehold.it/280x300",
"amount" : ""
}
]
}
The above is json which is fed into my page and then using ng-repeat it will display and then the amount
keys get updated when the user has clicked either +
or -
.
I would like to somehow update this json to be accessable throughout the site too so that when the user/client has updated it they can view a separate page which shows them the answers.
Solution
Used localStorage
to carry data from the $scope around
localStorage.setItem('data', angular.toJson($scope.data));