1

I m currently trying to open an AngularUI Bootstrap Modal. Somehow, I keep getting the following error:

Error: [$injector:unpr] Unknown provider: appMainProvider <- appMain

I search online and found several "solution" but none of them seem to work (or perhaps i m doing something wrong). One of the solution i found is this one.

This is my main js controller:

module.exports = function(appMain, name) {

    appMain.controller(name, mainCtrl);

    mainCtrl.$inject = ['$state', 'mainDataService', 'dnnVariables', '$uibModal'];

    function mainCtrl($state, mainDataService, dnnVariables, $uibModal) {

        var vm = this;

        function fullAnswer() {
            var source = require("../ViewAnswer/viewAnswer.html");
            $uibModal.open({
                templateUrl: source,
                controller: require("../ViewAnswer/viewAnswer.controller.js"),
                controllerAs: 'viewAnswerCtrl',
                backdrop: 'static'
            });
        }
    }
}

This opens the modal. The modal html is as following (barely anything for testing purpose)

something

The modal js controller is as following:

module.exports = function (appMain, name) {

appMain.controller(name, viewAnswerCtrl);

viewAnswerCtrl.$inject = ['$state', 'mainDataService', 'dnnVariables', "$uibModalInstance"];

function viewAnswerCtrl($state, mainDataService, dnnVariables, $uibModalInstance) {

    var vm = this;

    }
}

Note: I'm using angular-ui-bootstrap 2.5.

Cœur
  • 37,241
  • 25
  • 195
  • 267
B.Termeer
  • 315
  • 3
  • 18

1 Answers1

1

In this example mainCtrl is not controller function but some wrapper function that defines a controller. It is likely supposed to be used as:

mainCtrl(appMain, name);

instead of

appMain.controller(name, mainCtrl);

There's no benefit in wrapping controllers in module.exports = function (appMain, name) {...}. It should be preferably omitted, and angular.module(...) should be used instead of appMain variable.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • It should affect the error. The error results from that you pass `function (appMain, name) {` function as argument to `controller`, etc. If you do this in several places, all of them should be fixed. – Estus Flask Apr 10 '18 at 08:38
  • missedtypes something. fixed it. Thanks – B.Termeer Apr 10 '18 at 09:10