Angularjs变量值没有第一次更新,sweetAlert成功

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;
});

点赞