4

我使用了 AngularJS v1.5.3 & vendor.bundle.js 和 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;
            });
        };
4

1 回答 1

2

尝试使用以下功能可能会有所帮助。

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

我在 .then 中添加了以下函数

$scope.$apply(function () { $scope.displayDiv=1; });

于 2017-06-14T05:19:44.010 回答