0

我有一个取消按钮,当从表中选择一个项目时该按钮会被激活。我想在按下取消时显示一个警报,询问用户是否确认他要取消。如果他确定,则该行被删除,否则警报关闭。

我有以下代码但不工作,没有弹出警报。

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

这是我的 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)
               }
            });
         }
      };

   }])

}());

我在标签中有这个脚本<head>,我不确定它是否有用。只是从其中一个修复程序中复制它。

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

myCancel

到目前为止,函数具有 nthg。另外,如果用户确定要取消,我该如何删除该行。

我从某人那里得到了上面的代码,但似乎不起作用。请帮忙。

4

1 回答 1

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

试试这个......

于 2016-10-07T10:02:22.553 回答