I used AngularJS v1.5.3 & vendor.bundle.js and app.bundle.js
在此单击显示按钮并显示 swal 确认框,我按下“是,显示它!”按钮和 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;
});
};
最佳答案
Try with below function may be help.
<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;
});
});
};
I have add below function in .then
$scope.$apply(function () { $scope.displayDiv=1; });
关于Angularjs 变量值第一次使用 sweetAlert 时未更新,成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44522459/