简体   繁体   中英

How to show angular bootstrap-modal on page load only once?

I can show the bootstrap modal on page load, the modal is triggering even when route changed. like if i returned to the same page from other page using browser back button or forward button. if it shows on page reload, that is ok to me, but on route change also it is showing.
this is the code i am using to show on page load.i have tried some solutions online but didn't worked.it may be the possible duplicate. but the other solutions not working for me. i have tried with onroutechangestart -->to hide, but it is still showing, how to do it . can anyone please help me.

angular.element(document).ready(function () {
   $scope.showModal = true;
});

You could create a factory which control the state of your app

app.factory('startFact',function(){

        var isStarted = false;

        return{
            isStarted: function(){
                return isStarted;
            },

            startApp: function(){
                isStarted = true;
            },
        };
    });

In the controller

app.controller('mainCtrl', ['$scope','startFact', function ($scope, startFact) {
        $scope.init = function () {

            if (!startFact.isStarted()) {
                $scope.showModal = true;
                startFact.startApp();
            }
        };
    }]);

Call the init function

<body ng-controller="mainCtrl" ng-init="init()">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM