First click on toggle doesn't change its checked value

I find that toogle’s first click doesn’t change its checked value, and the following clicks change its situation, and the value is reverse from the widget.

Here is my template:

	<ion-toggle ng-repeat="item in settingList" ng-model="item.checked" ng-checked="item.checked" ng-change="saveSettings()">{{ item.text }}</ion-toggle>

And In my controller:

$scope.settingList = [
{text:"Auto Sign In", checked:localStorage.getItem('SETTING.autoSignIn')=='true'},

//setting change functions
$scope.saveSettings = function(){
	//auto Sign In

Thank you~

Hmm, I got click events working in my example.

Is this on a device or in the browser? Also what version of ionic are you using?

Thank you for answering my question.
em…I am using the beta6 in desktop Chrome, and now I find that it works well in value’s change.(use ng-bind, json filter to see the changes). The problem maybe a misunderstanding of the Angular’s ng-change, the function it trigger operated before the value changed, so I get the wrong value. I am new to AngularJS too, maybe I need an extra parameter or use $watch to make it get actual value.
Thanks. Ionic is really good~

Hi there,
I experienced some strange behavior on your toggles.
If I initalize a toggle with value false, everything works fine, but if I initialize it with true, the first change will get ignored.

I really don’t understand this.

I had the similar problem. That was the problem my model was initialised as string (read from localstorage) instead of boolean.

Check the following codepen:


1 Like

Thank you very much Barkoczi for your contribution, I had the same problem and I was going crazy.