Angularjs variable value is not updated the first time sweetAlert succeeds

I used AngularJS v1.5.3 and vendor.bundle.js and app.bundle.js

in this click to display the button and display the swal confirmation window, and I clicked "Yes, display it!" and the div is not displayed, but I click the second time and then show this div, I mean the value of $ scope.displayDiv changes, but no first-time effects please give me a solution

Here I insert my code:

<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
source share
1 answer

Trying with the function below may 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 a function below in .then

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

+1

Source: https://habr.com/ru/post/1679150/


All Articles