I made this simple test with ionic toggle but my alert return False when is True and True when is false. Any ideas?
http://codepen.io/anon/pen/jtKCf
$scope.pushNotificationChange = function() {
alert('Push Notification Change: '+ $scope.pushNotification.checked);
};
Your code is fine this just happens to be a tedious timing issue. The official example here suffers the same issue as yours if you look at the console log it outputs.
Here is a CodePen I made that works using $timeout
that solves this issue.
$scope.pushNotificationChange = function() {
$timeout(function() {
alert('Push Notification Change: '+ $scope.pushNotification.checked);
}, 0);
};
/edit
Here is another working approach that I made after seeing tasseKATT's comment.
$scope.$watch('pushNotification.checked', function(newValue, oldValue) {
console.log('Push Notification Change: ' + newValue);
});
You can avoid needing the ng-change
using this alternative approach.