【问题标题】:passing variables into angular-ui modal将变量传递到 angular-ui 模态
【发布时间】:2016-02-13 04:06:00
【问题描述】:

我在从 angular-ui 文档转移模态示例时遇到了一些问题:https://angular-ui.github.io/bootstrap/#/getting_started

我一直遇到这个错误:

参数 'ModalInstanceCtrl' 不是函数,未定义

控制者:

  (function () {
    'use strict';

    angular
        .module('projMgrApp')
        .controller('forumController', forumController)

    forumController.$inject = ['$scope', '$window', '$uibModal', 'Notices'];

    function forumController($scope, $window, $uibModal, Notices) {
        $scope.Notices = Notices.query();
        $scope.successText = "Temp Success Message";
        $scope.MessageTitle = "Temp Msg Title";
        $scope.MessageText = "Temp Msg Text";

        angular.module('projMgrApp').controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, MessageText, messageTitle) {
            $scope.MessageText = MessageText;
            $scope.MessageTitle = MessageTitle;
            $scope.ok = function () {
                $uibModalInstance.close();
            };

            $scope.cancel = function () {
                $uibModalInstance.dismiss('cancel');
            };
        });


        $scope.OnAddNoticeClick = function () {
            var EditNoticeModal = $uibModal.open({
                templateUrl: 'add-edit-modal.html',
                controller: 'ModalInstanceCtrl',
                resolve: {
                    MessageText: function () { return $scope.MessageText },
                    MessageTitle: function () { return $scope.MessageTitle }
                }
            });
        };
    }
})();

模态是从一个运行OnAddNoticeClick fn的ui按钮生成的。

【问题讨论】:

  • 你能发布你的ModalInstanceCtrl代码
  • 它在那里.. 我已经将它切换进和切换出论坛控制器 fn 以查看它是否有帮助.. 在上面的参考中它仍然在那里..
  • 我应该注意,当我在 forumController 之外切换时,我收到一个错误,即 MessageText 和 MessageTitle 未定义。
  • 您的 MessageTitle 参数有一个小写的“m”,但尝试使用大写的“M”引用它,这就是您收到 MessageTitle is undefined 错误的原因。

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


【解决方案1】:

我设法通过将控制器的样式切换为:

angular.module('projMgrApp')
    .controller('ModalInstanceCtrl', ModalInstanceCtrl);

ModalInstanceCtrl.$inject = ['$scope', '$uibModalInstance', 'MessageText', 'MessageTitle'];

function ModalInstanceCtrl($scope, $uibModalInstance, MessageText, MessageTitle) {
        $scope.MessageText = MessageText;
        $scope.MessageTitle = MessageTitle;
        $scope.ok = function () {
            $uibModalInstance.close();
        };

        $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
    };

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多