angularjs - 第一次加载时模态显示为空,第二次则不显示

标签 angularjs modal-dialog

编辑:我在这里重新创建了问题 http://plnkr.co/edit/w6yJ8KUvD3cgOrr56zH3?p=preview

我是 angularjs 新手,我正在尝试使用一些数据创建一个弹出模式..

我不明白为什么第一次打开它时它是空的,但第二次(等等)它很好。我所说的“好”是指标题就在那里。因此,每次重新加载页面时,第一次都是空的。

你能看到我错过了什么吗?

ModalController.js:

angular.module("Modal")
.controller("ModalController",
[
    "$scope", "$uibModal", "$log", "ModalService", "AuthenticationService",
    function($scope, $uibModal, $log, ModalService, AuthenticationService) {
        AuthenticationService.GetCurrentWindowsUser(function(username) {
            $scope.username = username;
        });

        $scope.openModal = function () {
            AuthenticationService.GetItems($scope.username, function(items) {
                $scope.items = items;
            });

            $scope.animationsEnabled = true;
            $uibModal.open({
                animation: $scope.animationsEnabled,
                templateUrl: 'modals/items.html',
                controller: 'ModalInstanceController',
                size: 'lg',
                resolve: {
                    funds: function() {
                        return $scope.items;
                    }
                }
            });
        };
    }
])
.controller('ModalInstanceController', function($scope, $uibModalInstance, items) {

    $scope.items = items;

    $scope.ok = function() {
        $uibModalInstance.close();
    };

});

items.html:

<div class="container" ng-controller="ModalController">
<script type="text/ng-template" id="modals/items.html">
    <div class="modal-header">
        <h3 class="text-centered">items</h3>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ok()">SELECT</button>
    </div>
</script>

</div>

首页.html:

<div class="container" ng-controller="ModalController">
<button type="button" class="btn btn-default" ng-click="openModal()">Large modal</button>
</div>

最佳答案

我设法通过删除我想要显示的模式中的脚本标签来解决这个问题

    <div class="modal-header">
        <h3 class="modal-title">I'm a modal!</h3>
    </div>
    <div class="modal-body">
        <ul>
            <li ng-repeat="item in items">
                <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
            </li>
        </ul>
        Selected: <b>{{ selected.item }}</b>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
    </div>

http://plnkr.co/edit/D4B6puSS2Z9j4DPPBTWx?p=preview

关于angularjs - 第一次加载时模态显示为空,第二次则不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34092276/

相关文章:

像iOS 13模态全屏一样的Flutter过渡

modal-dialog - Gridview View 和更新按钮上的 Yii2 模式对话框显示两个按钮的相同内容

WPF 从 UserControl 打开模态窗口

javascript - w3schools 模态动画关闭

mysql - PHP MySQL 数据到 AngularJS

javascript - 我可以在 html 中初始化 Angular ngModel,然后在 Controller 中使用它的值吗?

javascript - 如何在大型应用程序中避免许多 "$routeProvider.when"

javascript - 在angular Js中加载模块时出错

javascript - AngularJS - 在没有 jQuery 的指令中将 HTML 元素添加到 dom

ios - 从 UIViewcontroller 调用 Storyboard