angularjs - Ionic Toggle returning wrong value -
i made simple test ionic toggle alert return false when true , true when false. ideas?
http://codepen.io/anon/pen/jtkcf $scope.pushnotificationchange = function() { alert('push notification change: '+ $scope.pushnotification.checked); };
your code fine happens tedious timing issue. the official example here suffers same issue yours if @ console log outputs.
here codepen made works using $timeout
solves issue.
$scope.pushnotificationchange = function() { $timeout(function() { alert('push notification change: '+ $scope.pushnotification.checked); }, 0); };
/edit
here working approach made after seeing tassekatt's comment.
$scope.$watch('pushnotification.checked', function(newvalue, oldvalue) { console.log('push notification change: ' + newvalue); });
you can avoid needing ng-change
using alternative approach.
Comments
Post a Comment