为什么在将数组传递给模态时会出现角度未知的提供程序注入器错误?

时间:2016-08-10 17:40:31

标签: javascript angularjs

当我尝试打开一个以数组作为参数的模态时,我不断收到此错误:https://docs.angularjs.org/error/ $ injector / unpr?p0 = listItemsProvider%20%3C-%20listItems%20%3C-%20SingleActionListModalCtrl < / p>

这是控制器:

controller('SingleActionListModalCtrl', ['$scope', '$uibModalInstance', 'modalTitle', 'modalText', 'listItems', 'cancelBtnCaption', 'cancelBtnFunction',
function ($scope, $uibModalInstance, modalTitle, modalText, listItems, cancelBtnCaption, cancelBtnFunction) {

    $scope.modalTitle = modalTitle;
    $scope.modalText = modalText;
    $scope.list = listItems;
    $scope.cancelBtnCaption = cancelBtnCaption;

    $scope.cancel = function () {
        cancelBtnFunction();
        $uibModalInstance.close();
    };
}]).

这里是模态的视图:

<div>
    <script type="text/ng-template" id="EventFooterSingleActionListModal">
        <div class="modal-header">
            <h3 class="modal-title">{{ modalTitle }}</h3>
        </div>
        <div class="modal-body">
            {{ modalText }}
            <ul>
                <li ng-repeat="listItem in list track by $index">{{ listItem }}</li>
            </ul>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" type="button" ng-click="cancel()">{{ cancelBtnCaption }}</button>
        </div>
    </script>
</div>

这是功能定义:

    ModalFactory.OpenSingleActionListModal = function (modalName, title, msg, listItems, cancelCaption, cancelFunction) {
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: modalName,
            controller: 'SingleActionListModalCtrl',
            size: null,
            resolve: {
                modalTitle: function () {
                    return title;
                },
                modalText: function () {
                    return msg;
                },
                list: function() {
                    return listItems;
                },
                cancelBtnCaption: function () {
                    return cancelCaption;
                },
                cancelBtnFunction: function () {
                    return cancelFunction;
                }
            }
        });
    }

这是函数调用:

                    ModalFactory.OpenSingleActionListModal('EventFooterSingleActionListModal',
                        'Modal title', 'Modal text',
                         ['list item 1', 'list item 2'],
                        'Close', function () { });

1 个答案:

答案 0 :(得分:1)

在您的控制器中,您将其命名为listItems,并在您的解析中list