2015-11-02 70 views

回答

2

您可以創建這樣一個direcftive:

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

你使用這種方式:

<button confirmed-click="YourFunction()" ng-confirm-click="Are you really sure you want to do this ?">Action</button> 
+0

由於其工作對我來說.. –

+0

@RaviShah請給予好評/接受的答案,如果你的作品:) – IggY

+0

你肯定..但我新的堆棧流..所以這是我的第一個問題,因此,不能接受在一些聲譽的堆棧流.. –