Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

notification.confirm callback function called always

I am calling the notification.confirm of phonegap while using angular-js.

I have code as :

ng-click= func(item)

$scope.func = function(item) {
navigator.notification.confirm('Delete?', func2(item));
}

function func2 (item) {
console.log("Ohk call");
}

I want the func2 to be called only when the user presses the confirm button on the confirm box. But what happens is that it gets called as soon as the notification appears without the click of any button. How to resolve this?

like image 582
Bhumi Singhal Avatar asked Apr 29 '13 10:04

Bhumi Singhal


2 Answers

Here is the correct ans to it :

$scope.func= function (item) {
        navigator.notification.confirm('Delete?', function(button) {
            if ( button == 1 ) {
                func2(item);
            }
        });
    };

The value of button is the 1 / 2 based of which of the buttons, 'Confirm'/'Cancel' is clicked. In my case 'confirm' button had the value of 1 and so the equality check.

like image 85
Bhumi Singhal Avatar answered Nov 15 '22 16:11

Bhumi Singhal


That's because you are already invoking the function func2 inside the func. You just need to pass a function as an argument, not call it:

$scope.func = function(item) {
    navigator.notification.confirm('Delete?', function() {
        func2(item)
    });
}

This way the function will only be invoked when you confirm the notification.

like image 2
Wagner Francisco Avatar answered Nov 15 '22 15:11

Wagner Francisco