【问题标题】:AngularJs - modal window w/ajax loadingAngularJs - 带 ajax 加载的模式窗口
【发布时间】:2013-10-07 21:10:57
【问题描述】:

我正在尝试使用 ui.bootstrap (http://angular-ui.github.io/bootstrap/#/modal) 为应用程序上显示更多信息(包括 cmets 等内容)的元素启用模式窗口。该元素正在页面上作为指令加载,我认为我遇到了嵌套范围的问题,但是它看起来好像正在触发模式窗口,但没有出现任何内容(屏幕消失)。

我的指令如下所示:

    .directive('artifactCause', function() {
        return {
            restrict: 'E',
            replace: true,
            scope: {
                thing: '=thing'
            },
            templateUrl: 'views/directives/artifact-cause.html',
            controller: function($scope, $element, $attrs, $modal) {
                console.log('clicked');
                $scope.open = function() {

                    var modalInstance = $modal.open({
                        backdrop: true,
                        keyboard: true,
                        controller: 'artifactModalCtrl',
                        templateUrl: 'views/directives/modal-artifact.html',
                        scope: $scope,
                        resolve: {
                            thing: function () {
                                return $scope.thing.cause_id;
                            }
                        }
                    });

                };
            }
        };
    });

artifactModealCtrl 控制器如下所示:

.controller('artifactModalCtrl', function($scope, $http, loggedStatus, thing) {
        var token = loggedStatus.token();
        $scope.close = function(result) {
            dialog.close(result);
        };

        $http.get( REQUEST_URL + '/Artifact/ArtifactDetail?token=' + token + '&artifact_id=' + thing ).
            success(function(data) {
                console.log(data);
                $scope.thing = data.response;
                return data.response;
            }).
            error(function(data) {
                console.log('Error');
                console.log(data);
            });
    })

我知道我从我的 ajax 调用接收到的数据是成功的,因为我可以将它记录到控制台。任何正确方向的见解或指示将不胜感激。

【问题讨论】:

  • 你是否包含了用于引导的 css?
  • @lucuma 是的,我让它在不同的页面上运行,没有附加任何控制器。你觉得是造型问题?我觉得奇怪的是我可以看到元素出现在我的浏览器上,但没有显示在页面上,但是我不确定这是否是 JS 问题..
  • 我遇到了类似的问题,这是因为样式。如果模式附加到您的文档正文中,请检查检查器
  • @lort 文档正文中添加了 2 个模态 div,但正文标签上没有应用“模态”类,这是您的意思吗? - 调用 open 函数时,站点变灰(应该如此),只是没有模式窗口出现。不幸的是,模态 HTML 似乎缺少勇气:(
  • 我试图重现你的错误,但它似乎工作得很好:plnkr.co/edit/fLWAarDeP3ij1NrCqZiZ

标签: javascript jquery ajax twitter-bootstrap angularjs


【解决方案1】:

这很可能是找不到 HTML 模板的问题。模式正在启动并淡出屏幕,但找不到模板,因此屏幕上没有显示任何内容。

我个人在 templateUrl 属性中引用模板的文件位置没有成功,所以我所做的是将 html 模板包含在母版页或任何将触发模式的页面中,如下所示:

<div ng-include src="'../views/directives/modal-artifact.html'">

确保您的模板路径准确无误,您应该能够通过在页面加载时通过 firebug(或类似的浏览器开发工具)查看文件内容来确认这一点。

接下来,假设你的模板标签的id属性是"modal-artifact.html" (&lt;script type="text/ng-template" id="modal-artifact.html"&gt;),设置你的templateUrl如下:

templateUrl: 'modal-artifact.html' //this must match the id of your template

【讨论】:

  • 感谢您的建议,但我可以看到模板正在通过网络选项卡正确加载。好主意。
猜你喜欢
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多