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.
– Tedsville Oct 07 '16 at 09:58