samedi 26 novembre 2016

angularjs and localstorage, toggle bouttom

I'm trying to make a application with Ionic Framework. I'm arrived on a point or I have to make a List of toggle buttom and I want to store if the buttom is checked or not, but I want to store then 1 by 1 not all in the same time. That look like that : http://ift.tt/2grWifj

When i press the first toggle or a other, my code checked every checkbox :/ not only 1. And in the second part when I leave the page and return on it that doesn't store if the checkbox is checked . here's my html code for the toggle:

<label class="toggle" ng-model="infoTeamCtrl" ng-click="addidMatch(match.data.fixtures[$index].homeTeamName, match.data.fixtures[$index].result.goalsHomeTeam, match.data.fixtures[$index].result.goalsAwayTeam, match.data.fixtures[$index].awayTeamName)">
    <input type="checkbox" ng-model="favorite.checked" ng-change="favoriteChange()" > 
    <div class="track">
        <div class="handle"></div>
    </div>
</label>

my controller look like that :

// Loads on page load/controller load
$scope.favorite["checked"] = localStorage.getItem("favorites");

// If never set
if($scope.favorite.checked == null) {
    $scope.favorite.checked = true;
}

// Save
$scope.favoriteChange = function() {
    localStorage.setItem("favorites", $scope.favorite.checked);
}

  $scope.addidMatch = function(infoMatchHomeTeam, infoMatchGoalHomeTeam, infoMatchGoalAwayTeam, infoMatchAwayTeam) {
    $i = $i +1
    $localStorage[$i] = {
      infoMatchHomeTeam, infoMatchGoalHomeTeam, infoMatchGoalAwayTeam, infoMatchAwayTeam
    }
  };

Thank for you comprehension.




Aucun commentaire:

Enregistrer un commentaire