0

I have a Cancel button which gets activated when an item is selected from a table. I want to display an alert when Cancel is pressed which asks if the user is confirm he wants to cancel. If he is sure then the row gets deleted, else the alert closes.

I have the below code but is not working, no alert is popped up.

<button ng-click="myCancel()" ng-disabled="countChecked()!=1" confirmed-click="cancel(id)">Cancel</button><br><br>

And this is my js

(function() {
var app = angular.module('app', []);
app.controller('SidebarController', function($scope, $http, $window) {


$scope.cancel=function(id){
        $window.location.href = 'cancel/'+ id;
    }
})

app.directive('ngConfirmClick', [
   function(){
      return {
         link: function (scope, element, attr) {
            var msg = attr.ngConfirmClick || "Are you sure you want to cancel?";
            var clickAction = attr.confirmedClick;
            element.bind('click',function (event) {
               if ( window.confirm(msg) ) {
                  scope.$eval(clickAction)
               }
            });
         }
      };

   }])

}());

I have this script in the <head> tags, which I am not sure is useful. Just copied it from one of the fixes.

<script>document.write('<base href="' + document.location + '" />');</script>

The

myCancel

function has nthg as of now. Also how do I go about deleting the row if the user is sure to cancel.

I got the above code from someone but doesn't seem to work. Please help.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Tedsville
  • 21
  • 1
  • 5
  • I found a mistake....The confirm click directive is used wrong. It is not "confirmed-click" but "ng-confirm-click". However no message is displayed – Tedsville Oct 07 '16 at 09:52
  • Hey, looks like you have to use both the directives - confirmed-click and ng-confirm-click. This got it working-

    – Tedsville Oct 07 '16 at 09:58

1 Answers1

0
 $scope.cancel=function(id){
    if (confirm("Are you sure for cancelation?")) {
        $window.location.href = 'cancel/'+ id;
    }
 }

Try with this....

Umakant Mane
  • 1,001
  • 1
  • 8
  • 9
  • didn't help, the table vanishes when i use this... But i got it fixed b'fore, see the comments. Thanks anyway. This runs independently though – Tedsville Oct 07 '16 at 10:10