简体   繁体   English

如何仅在页面加载中显示一次角度引导模式?

[英]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. 这是我用来显示在页面load.I上的代码。我已经在线尝试了一些解决方案,但是没有用。可能是重复的。 but the other solutions not working for me. 但是其他解决方案对我不起作用。 i have tried with onroutechangestart -->to hide, but it is still showing, how to do it . 我已经尝试过onroutechangestart->隐藏,但是它仍在显示如何实现。 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 调用init函数

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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