Angularjs 第一次使用 sweetAlert 成功时变量值未更新
Angularjs variable value is not updating first time with sweetAlert is success
I used AngularJS v1.5.3 & vendor.bundle.js and app.bundle.js
在此单击以显示按钮并显示 swal 确认框,我按下 'Yes, display it!' 按钮并且 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;
});
I used AngularJS v1.5.3 & vendor.bundle.js and app.bundle.js
在此单击以显示按钮并显示 swal 确认框,我按下 'Yes, display it!' 按钮并且 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; });