I am currently in the process of learning angular as I develop a web application that resembles a todo list, specifically focused on football teams. In this application, users can navigate through a menu to select a league from four options. The application then retrieves data based on the league selected and displays a list of teams with checkboxes. Users can check off the football grounds they have visited during the season.
While the functionality works smoothly, I am looking for guidance on how to store user selections using localStorage and retrieve them upon page load.
Initially, I attempted to use the ng-change() method but encountered issues with displaying the correct data for each league due to retrieving the same data from localStorage instead of the JSON file corresponding to the ID. Any advice or assistance on resolving this would be highly appreciated!
Below is the HTML markup containing the teams and checkboxes:
<ul class="list-unstyled">
<li ng-repeat="club in league" ng-click="selectClub(club.id)">
<input type="checkbox" ng-model="club.done">
<a href="#/team">{{club.club}} - {{club.ground}}</a>
</li>
</ul>
Here is the controller code responsible for fetching the league ID and loading the data:
trackerControllers.controller('ClubCtrl', ['$scope', '$http', function($scope, $http) {
var leagueId=sessionStorage.getItem("leagueId");
$http.get('JSON/Leagues/league'+leagueId+'.json').success(function(data) {
$scope.league = data;
});
}]);
If there are any suggestions to improve the clarity of my question, please feel free to provide them. Thank you!
To better visualize the site, here is the link to the new version:
For reference, here is the link to the old version where data was stored differently: