Legion
Legion

Reputation: 3427

Why am I getting an angular unknown provider injector error when passing an array to a modal?

I keep getting this error when trying to open a modal that takes an array as a parameter: https://docs.angularjs.org/error/$injector/unpr?p0=listItemsProvider%20%3C-%20listItems%20%3C-%20SingleActionListModalCtrl

Here's the controller:

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();
    };
}]).

Here's the view for the modal:

<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>

Here's the function definition:

    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;
                }
            }
        });
    }

And here's the function call:

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

Upvotes: 0

Views: 75

Answers (1)

Marc Hughes
Marc Hughes

Reputation: 5858

In your controller, you named it listItems, in your resolve it's list

Upvotes: 1

Related Questions