2017-04-08 11 views
0

ng-confirm-clickが機能しない理由を教えてください。角度確認のクリックが機能しない

<div ng-controller="MainCtrl" ng-init="show=true;"> 
    <p >Hello {{name}}!</p> 
    <button ng-show="show" confirmed-click="changes();show=false;" ng-confirm-click="Confirm change?">change</button> 
</div> 

ボタンを非表示にする必要があります。

ここ例:

<!DOCTYPE html> 
<html> 

    <head> 
    <meta charset="utf-8" /> 
    <title>AngularJS Plunker</title> 
    <script>document.write('<base href="' + document.location + '" />');</script> 
    <link rel="stylesheet" href="style.css" /> 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
    <script src="app.js"></script> 
    </head> 

    <body ng-app = "plunker"> 
    <div ng-controller="MainCtrl" ng-init="show=true;"> 
     <p >Hello {{name}}!</p> 
     <button ng-show="show" confirmed-click="changes();show=false;" ng-confirm-click="Confirm change?">change</button> 
    </div> 
    </body> 

</html> 
+0

私はそれが動作する例を編集しました – aramadhani

答えて

0

代わりscope.$evalの使用scope.$apply及びコントローラからscope.$apply不要を取り除きます。ドキュメントから

$ evalのをこのように使用する:スコープの$のeval()は、スコープの賛成で廃止されるようです$スコープを使用し、修正機能を実行し、更新するように適用されます。後で見る。

Plunker

2

、HTML内

この作業コードを試してみてください。

<div ng-confirm-click="Are you sure to delete this product ?" confirmed-click="deletePost(data.postId)"> <span class="glyphicon glyphicon-trash"></span></div> 

app.jsファイルでは、(変更なし)以下のコードを置く:

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.$eval(clickAction) 
        } 
       }); 
      } 
     }; 
}]) 
関連する問題