Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 返回错误值的离子开关_Angularjs_Ionic Framework - Fatal编程技术网

Angularjs 返回错误值的离子开关

Angularjs 返回错误值的离子开关,angularjs,ionic-framework,Angularjs,Ionic Framework,我用ionic toggle做了这个简单的测试,但是我的警报在为真时返回False,在为假时返回True。有什么想法吗 http://codepen.io/anon/pen/jtKCf $scope.pushNotificationChange = function() { alert('Push Notification Change: '+ $scope.pushNotification.checked); }; 您的代码很好,这只是一个乏味的时间问题 使用解决此问题的$tim

我用ionic toggle做了这个简单的测试,但是我的警报在为真时返回False,在为假时返回True。有什么想法吗

http://codepen.io/anon/pen/jtKCf


$scope.pushNotificationChange = function() {
    alert('Push Notification Change: '+ $scope.pushNotification.checked);
};

您的代码很好,这只是一个乏味的时间问题

使用解决此问题的
$timeout

$scope.pushNotificationChange = function() {
    $timeout(function() {
        alert('Push Notification Change: '+ $scope.pushNotification.checked);
    }, 0);
};
/编辑

在看到塔塞卡特的评论后

$scope.$watch('pushNotification.checked', function(newValue, oldValue) {
  console.log('Push Notification Change: ' + newValue);
});

使用这种替代方法,您可以避免需要更改
ng

您的代码很好,这只是一个冗长的时间问题

使用解决此问题的
$timeout

$scope.pushNotificationChange = function() {
    $timeout(function() {
        alert('Push Notification Change: '+ $scope.pushNotification.checked);
    }, 0);
};
/编辑

在看到塔塞卡特的评论后

$scope.$watch('pushNotification.checked', function(newValue, oldValue) {
  console.log('Push Notification Change: ' + newValue);
});

使用这种替代方法,您可以避免使用
ng更改

@PedroMarques我投票支持您,这是一个狡猾的问题。我不确定你是否能接受答案,但当你有能力时,请接受,谢谢!Ionic在内部使用了大量的
setTimeout
,这导致了类似的情况。与其使用
$timeout
将某些内容放在浏览器事件队列的末尾,不如完全跳过
ng change
,并使用
$watch
在值实际更改时获得通知。@tasseKATT谢谢,我更新了提供此替代方法的答案。没问题:)+1来自我。@PedroMarques我投票支持你,这个问题很狡猾。我不确定你是否能接受答案,但当你有能力时,请接受,谢谢!Ionic在内部使用了大量的
setTimeout
,这导致了类似的情况。与其使用
$timeout
将某些内容放在浏览器事件队列的末尾,不如完全跳过
ng change
,并使用
$watch
在值实际更改时获得通知。@tasseKATT谢谢,我更新了提供此替代方法的答案。没问题:)+1。