Ion-checkbox not refresh

Hi All!

I have settings view, data come from database (answer up). There are two checkbox: notification and news , if data is ‘1’ then checkbox checked, if the data is ‘0’ then checkbox unchecked, thats work fine. (from database: 1, 1 so two checkbox are checked)
When i click one checkbox, that unchecked, after go other state and go back settings state, the two checkbox no changed checked, checked…, but http.get is in $ionicView.enter, so alwas run, if i click this state, this refresh but checbox not changed to original status
Reload button: state.reload(‘settings’), this refresh but checbox not changed to original status
From database display always fresh data…
Thanks! (sorry my english :slight_smile: )

change you html like below and bind your updated value in ng-model

<input type="checkbox" name="name" ng-model="Model_Name" ng-true-value="'true'" ng-false-value="'false'" ng-checked="checkbox == "'true'"" >

Hi, my code :

<ion-checkbox ng-model="checkboxNoti" ng-true-value="'1'" ng-false-value="'0'">E-mail notification</ion-checkbox>


$scope.$on('$ionicView.enter', function(){
      //get user data
      $http.get('http://php/settings.php').success(function(data) {
      	$scope.checkboxNoti = data.notification; //data.notification = 1

so what is the different? The checkbox value ok, when load state, but if i click on checkbox, this unchecked, and go other state and go back this state, the checkbox value is the last clicked, not from $http.get data, this data is fresh every state load

Now i get that, Wrap your code inside $scope.$apply for changing the value of checkbox
like this

$http.get('http://php/settings.php').success(function(data) {
$scope.checkboxNoti = data.notification;

//data.notification = 1

I see this, but display error with this code.
I found the solution: ng-change

<ion-checkbox ng-model="checkboxNoti" ng-true-value="'1'" ng-false-value="'0'" ng-change="check1(checkboxNoti)">E-mail notification</ion-checkbox>

$scope.check1 = function(value1) {
        $scope.checkboxNoti = value1;

this work :slight_smile:

1 Like