2017-06-13 64 views
4

我用AngularJS V1.5.3 & vendor.bundle.js和app.bundle.jsAngularjs變量值沒有更新第一次與sweetAlert是成功

在該點擊,以顯示按鈕和顯示SwaI位確認框,我按'是,顯示它!'按鈕和DIV沒有顯示,但是,我按第二次則顯示這個div,我的意思是$ scope.displayDiv值改變但第一次 沒有任何影響,請給我解決

在這裏,我貼我的代碼:

<div class="input-group" ng-show="displayDiv" > 
     DOM data 
</div> 
<button class="" ng-click="disDiv()">Show</button> 


    $scope.displayDiv=0; 
    $scope.disDiv = function() { 
      swal({ 
       title: 'Are you sure?', 
       text: "You won't to display", 
       type: 'warning', 
       showCancelButton: true, 
       confirmButtonColor: '#3085d6', 
       cancelButtonColor: '#d33', 
       confirmButtonText: 'Yes, display it!', 
       cancelButtonText: 'No, cancel!', 
       confirmButtonClass: 'btn btn-success', 
       cancelButtonClass: 'btn btn-danger', 
       buttonsStyling: false 
      }).then(function() { 
       $scope.displayDiv=1; 
      }); 
     }; 
+2

請不要在angularjs相關問題上使用角標記 –

+1

成功事件不在角度世界。用戶$ scope。$ apply – seyfside

+0

非常感謝'seyfside',它的工作正常... –

回答

1

試試下面的函數可能會有所幫助。

<div class="input-group" ng-show="displayDiv" > 
     DOM data 
</div> 
<button class="" ng-click="disDiv()">Show</button> 


    $scope.displayDiv=0; 
    $scope.disDiv = function() { 
      swal({ 
       title: 'Are you sure?', 
       text: "You won't to display", 
       type: 'warning', 
       showCancelButton: true, 
       confirmButtonColor: '#3085d6', 
       cancelButtonColor: '#d33', 
       confirmButtonText: 'Yes, display it!', 
       cancelButtonText: 'No, cancel!', 
       confirmButtonClass: 'btn btn-success', 
       cancelButtonClass: 'btn btn-danger', 
       buttonsStyling: false 
      }).then(function() { 
       $scope.$apply(function() { 
         $scope.displayDiv=1; 
        }); 
      }); 
     }; 

我有添加以下功能中。然後

$ $範圍應用(功能(){$ scope.displayDiv = 1; })。

+0

非常感謝,它正在工作...... –

相關問題