1

I'm having some issues transferring the modal example from the angular-ui documentation here: https://angular-ui.github.io/bootstrap/#/getting_started

I keep running into this error:

Argument 'ModalInstanceCtrl' is not a function, got undefined

controller:

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

the modal is spawned from a ui button that runs the OnAddNoticeClick fn.

4
  • can you post your ModalInstanceCtrl code Commented Feb 13, 2016 at 4:16
  • its in there.. I've switched it in and out of the forum controller fn to see if it helped.. in the above reference its still in there.. Commented Feb 13, 2016 at 4:21
  • I should note that when I switch outside the forumController, I get an error that it MessageText and MessageTitle are undefined. Commented Feb 13, 2016 at 4:24
  • You have a lowercase "m" for your MessageTitle argument, but try to reference it with an capital "M," that's why you get a MessageTitle is undefined error. Commented Feb 13, 2016 at 4:30

1 Answer 1

1

I managed to get it to work by switching the style of controller to:

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');
        };
    };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.