notification.confirm callback function called always
Asked Answered
L

2

5

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?

Lynch answered 29/4, 2013 at 10:44 Comment(1)
Please provide the exact html piece with ng-click.Thema
L
9

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.

Lynch answered 6/5, 2013 at 6:31 Comment(0)
C
2

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.

Crowd answered 29/4, 2013 at 11:12 Comment(1)
Hey this does not work ...the function func2 gets called even when i click on the cancel buttonLynch

© 2022 - 2024 — McMap. All rights reserved.