質問

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?

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top