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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With