0

I'm trying to have a checkbox 'tick' its self depending on if the value data.notification is either true or false. I can see the variable is set in the console.log as true, however even with the data.model / checked it still doesn't work Here is my controller

.controller('ConfigCtrl', function($scope, $stateParams,$http,$timeout,$localStorage,StorageService) {
    $scope.data = {};    
    // Declare localStorage Variables to scope variables 
    $scope.data.claymore_api= window.localStorage.getItem('claymore_api');
    $scope.data.cam_api= window.localStorage.getItem('cam_api');
    $scope.data.rpi_api= window.localStorage.getItem('rpi_api');
    $scope.data.fire_api= window.localStorage.getItem('fire_api');

    $scope.data.notification= window.localStorage.getItem('notification');
    $scope.data.enable_cam= window.localStorage.getItem('enable_cam');
    $scope.data.enable_power= window.localStorage.getItem('enable_power');
    $scope.data.enable_fire= window.localStorage.getItem('enable_fire');
    $scope.data.casefire= window.localStorage.getItem('casefire');
console.log($scope.data.notification);
      $scope.add = function () {
        window.localStorage.setItem('claymore_api',$scope.data.claymore_api);
        window.localStorage.setItem('cam_api',$scope.data.cam_api);
        window.localStorage.setItem('rpi_api',$scope.data.rpi_api);
        window.localStorage.setItem('fire_api',$scope.data.fire_api);
      };

      $scope.settings = function () {
        window.localStorage.setItem('notification',$scope.data.notification);
        window.localStorage.setItem('enable_cam',$scope.data.enable_cam);
        window.localStorage.setItem('enable_power',$scope.data.enable_power);
        window.localStorage.setItem('enable_fire',$scope.data.enable_fire);
        window.localStorage.setItem('casefire',$scope.data.casefire);
        console.log(window.localStorage.getItem('notification'));
      };      
})

Here is the html

  <li class="item item-toggle">
     Notifications
     <label class="toggle toggle-positive">
       <input type="checkbox" ng-model="data.notification" checked="{{data.notification}}">
       <div class="track">
         <div class="handle"></div>
       </div>
     </label>
  </li>

5
  • Which of the console.log calls shows trooish value - the 1st one or the one in the settings function? Is the 'notification' value stored in the localStorage prior the controller initialization? Commented Jan 22, 2018 at 12:50
  • The first one console.log($scope.data.notification); Commented Jan 22, 2018 at 12:51
  • If you use ion-checkbox, e.g. here or there? Commented Jan 22, 2018 at 12:56
  • think the value should be 1 or 0 not true false, but i am not sure Commented Jan 22, 2018 at 13:59
  • Solved it don't worry - With true/false Commented Jan 22, 2018 at 14:14

0

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.