简体   繁体   English

AngularJS bootstrap.ui模式没有显示

[英]AngularJS bootstrap.ui modal not showing

I am trying to display a modal dialog using AngularJS bootstrap.ui. 我试图使用AngularJS bootstrap.ui显示模式对话框。 When I do a $modal.open(...) the screen grays out and the html from my templateUrl get called from the server, but no modal displays. 当我执行$ modal.open(...)时,屏幕灰显,我的templateUrl中的html从服务器调用,但没有模态显示。 When I click on the gray area, the modal "closes", that is the gray area goes away and the screen looks normal again. 当我点击灰色区域时,模态“关闭”,即灰色区域消失,屏幕再次显示正常。 I cannot figure out why I don't see any modal screen. 我无法弄清楚为什么我看不到任何模态屏幕。

I am trying to follow this tutorial: Angular directives 我正在尝试遵循本教程: Angular指令

I am using Visual Studio 2013, MVC 5, AngularJS 1.2.2. 我使用的是Visual Studio 2013,MVC 5,AngularJS 1.2.2。

I am using bootstrap.css that comes with the VS project. 我正在使用VS项目附带的bootstrap.css。 It has the modal classes in it. 它有模态类。 I am getting no error reported from the Javascript console. 我没有从Javascript控制台报告错误。 My app is defined as follows: 我的应用程序定义如下:

var blogApp = angular.module('blogApp', ['ngResource', 'ngSanitize', 'ui.bootstrap']) ...

blogApp.controller('blogController',
function blogController($scope, $modal, $log, blogData, userData) {

    ...

    $scope.showPrivacy = function() {
        $modal.open({
            templateUrl: '/Privacy',
            controller: 'PrivacyInstanceController'
        });
        return false;
    };
});


var PrivacyInstanceController = function($scope, $modalInstance) {
    $scope.close = function() {
        $modalInstance.close();
    };
}

And my markup is: 我的标记是:

<div ng-controller="blogController">
        <a ng-click="showPrivacy()">Privacy Policy</a>
    </div>

Any idea why my screen is graying out, the /Privacy resource is getting loaded and the screen returns to normal when the gray is clicked, but no modal appears? 知道为什么我的屏幕变灰,/ Privacy资源被加载,点击灰色时屏幕恢复正常,但是没有模态出现?

This is a incompatibility with ui.bootstrap and bootstrap 3.0. 这与ui.bootstrap和bootstrap 3.0不兼容。

You only need to put in your css: 你只需要输入你的css:

.modal {
display: block;
}

You can see this post for more detail: AngularJs with UI-Bootstrap: Fix broken dialog boxes . 你可以看到这篇文章了解更多细节: 带有UI-Bootstrap的AngularJs:修复损坏的对话框

I had the exact same issue. 我有完全相同的问题。 What I did to fix it was to change what i had in my template.html, the .html provided with the templateUrl property in the open-function. 我所做的是修改我在template.html中的内容,即open-function中的templateUrl属性提供的.html。

I had the full modal-markup there: 那里有完整的模态标记:

<div class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">And here some modal markup</div></div></div>

When I removed the first three divs and only had And here some modal markup left in the template.html it worked fine! 当我删除前三个div并且只有在And here some modal markup ,在template.html中留下了And here some modal markup ,它工作得很好!

Have exactly the same symptoms while ago. 在此之前有完全相同的症状。 Do not remember the exact details, but I think the main problem was that the instance of the modal has always display:none . 不记得确切的细节,但我认为主要的问题是模态的实例总是display:none

  1. Make sure that you are using the ui-bootstrap with templates ( ui-bootstrap-tpls.js ) -- as there is the effect of graying-out you probably do. 请确保您正在使用的ui-bootstrap使用模板( ui-bootstrap-tpls.js ) -因为有变成灰色的,你可能做的效果。
  2. In ui-bootstrap-tpls.js go to the modal template at the very bottom (you can find it by: "template/modal/window.html") and add there style="display:block". If it will not help try to match css classes of the template against your ui-bootstrap-tpls.js转到ui-bootstrap-tpls.jsmodal模板(你可以通过:“template / modal / window.html”找到它)并在那里添加style="display:block". If it will not help try to match css classes of the template against your style="display:block". If it will not help try to match css classes of the template against your bootstrap.css`. style="display:block". If it will not help try to match css classes of the template against your bootstrap.css`。

I personally used some custom version of bootstrap3 , and now have got these as template: 我个人使用了一些自定义版本的bootstrap3 ,现在已经将这些作为模板:

angular.module("template/modal/backdrop.html", []).run(["$templateCache", function($templateCache) {
  $templateCache.put("template/modal/backdrop.html",
    "<div class=\"modal-backdrop fade\" ng-class=\"{in: animate}\" ng-style=\"{'z-index': 1040 + index*10}\" ng-click=\"close($event)\"></div>");
}]);

angular.module("template/modal/window.html", []).run(["$templateCache", function($templateCache) {
  $templateCache.put("template/modal/window.html",
    "<div class=\"modal fade {{ windowClass }}\" ng-class=\"{in: animate}\" style='display:block;z-index:1050'  ng-transclude></div>");
}]);

EDIT You can easily remove from your bootstrap.css all styles in class modal (and its sub-classes) where display is set to none -- bootstrap just hides the DOM element, whereas ui-bootstrap removes it completely. 编辑你可以轻松地从你的bootstrap.css删除类modal (及其子类)中display设置为none所有样式 - bootstrap只隐藏DOM元素,而ui-bootstrap完全删除它。

The problem for me (developing with visual studio using bootstrap 4) was that the bootstrap class .fade:not(.show) defines opacity: 0 . 对我来说这个问题(使用引导程序4使用visual studio进行开发)是引导类.fade:not(.show)定义了opacity: 0 Using code inspector to disable this class, I could see that the modal would show. 使用代码检查器来禁用此类,我可以看到模式将显示。

However, in order to avoid modifying vendor files (namely, the bootstrap.css file), I simply extended the function that calls the modal to add the 'show' class to the modal page. 但是,为了避免修改供应商文件(即bootstrap.css文件),我只是扩展了调用模态的函数,将“show”类添加到模态页面。 In your example, this would be as follows: 在您的示例中,这将如下所示:

$scope.showPrivacy = function() {
    $modal.open({
        templateUrl: '/Privacy',
        windowClass: 'show',
        controller: 'PrivacyInstanceController'
    });
    return false;
};

Normally, adding the show class to the entire window would mean that the modal is displayed continuously. 通常,将show类添加到整个窗口将意味着连续显示模态。 This is not an issue when pages are loaded dynamically because the entire element with the .show class is removed when the user clicks away from the modal, irrespective of the existence of this class. 当动态加载页面时,这不是问题,因为当用户单击模态时,将删除具有.show类的整个元素,而不管此类是否存在。

由于一些奇怪的原因,模态的背景高度未设置为填充窗口,要在ui-bootstrap-tpls.js修复此问题,我转到底部的template/modal/backdrop.html行并将以下内容添加到样式中'width':'100%', 'height':'100%'

I upgraded to bootstrap v3.3.4 and now it works for me. 我升级到bootstrap v3.3.4,现在它适用于我。

  • Angularjs v1.3.12 Angularjs v1.3.12
  • ui-bootstrap-0.12.0 UI的引导-0.12.0
  • ui.bootstrap.tpls-0.12.0 ui.bootstrap.tpls-0.12.0

在我的情况下,问题是bower正在安装bootstrap 4而ui-modal支持3.3.7所以你需要检查bower_components上的bootstrap版本

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

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