【问题标题】:Show Angular UI Modal one second after opened打开后一秒显示 Angular UI 模态
【发布时间】:2017-12-15 12:47:23
【问题描述】:

In this plunk 我有一个 Angular UI 模式,当它打开时,它应该隐藏一秒钟然后显示。我在模板本身中使用ng-show,但这隐藏了内容,而不是模式。如何隐藏模态?请注意,模态显示在console.log("opened") 之后,无需等待console.log("displayed")

Javascript:

var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function () {});

app.directive("theModal", function($uibModal,$timeout) {
          return {
            restrict: "AE",        
            link: function (scope, element, attrs) {

                    scope.show = false;
                    console.log("opened");
                    scope.instance = $uibModal.open({
                        windowClass: 'app-modal',
                        template: '<div ng-show="show">MODAL WAS LOADED</div>'
                    });

                    $timeout(function(){
                      scope.show = true;
                      console.log("displayed");
                    },1000)

            }
        }
    });

【问题讨论】:

    标签: javascript angularjs angular-ui-bootstrap angular-ui


    【解决方案1】:

    试试这个

    var app = angular.module('app', ['ui.bootstrap']);
    app.controller('ctl', function () {});
    
    app.directive("theModal", function($uibModal,$timeout) {
          return {
            restrict: "AE",        
            link: function (scope, element, attrs) {
    
                    console.log("opened");
    
                    $timeout(function(){
                      scope.instance = $uibModal.open({
                        windowClass: 'app-modal',
                        template: '<div >MODAL WAS LOADED</div>'
                      });
                      console.log("displayed");
                    },1000)
    
            }
        }
    });
    

    【讨论】:

    • 不幸的是,这在我的情况下不起作用,在我使用超时作为将来完成的函数的问题中,但在我的真实场景中它不是超时,它是一个不同的函数。我需要等到这个函数结束,然后才将显示标志设置为 true。
    • ..and only then set the..,使用承诺
    • @svarog 是的,我可以使用 Promise,但是我仍然需要在模式级别而不是在内容级别设置 show/hide 标志,这是主要困难。
    猜你喜欢
    • 2014-06-27
    • 2020-08-05
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 2017-03-24
    • 2014-07-11
    相关资源
    最近更新 更多