Angular is giving me an injection unresolved error, but my controller isn't asking for any injections

138 views Asked by At

I have a modal controller that is buggy, so I've been commenting out code to try to figure out the bug. Currently, my modal HTML partial is an empty div tag and my controller is a single console.log, with no arguments or parameters. The $modal.open call only specifies the controller and the partial.

Now, when I try to open the modal I get an injector error saying that 'orgId' is not resolving. Except I'm not asking for orgId to be injected. I've already cleared the cache (Chrome), ensured that I'm running the correct, latest version of the file, and deleted all (commented or not) instances of the word 'orgId' from the file. Yet it keeps asking for it. As a modal controller, it's not in my router-ui state hierarchy, so it shouldn't be any weird parent-child interaction. Any other ideas of what could be going on?

This is what my code looks like:

Partial.html:
<div></div>

Controller:
app.controller( 'ctrl.modal', [ function () { console.log("Controller is called"); } ] )

Calling Controller:

    exercises.controller( 'ctrl.exercisesnew', [ '$scope', '$location', '$stateParams', 'factory.exercises', 'force.services.userservice', '$q',
        '$resource', 'factory.endpoints', '$modal', 'underscore', 'force.factory.classes.usercontext', 'factory.common', 'force.services.unitservice', '$state', 'factory.teep', '$window',
        function ( $scope, $location, $stateParams, ExercisesServices, UserService, $q, $resource, endpoints, $modal, _, UserContext, commonService, UnitService, $state, TeepService, $window ) {
            $scope.c2ram.ctrl.exercisesnew.absorb = function () {
                var assignExerciseDetailsModalInstance = $modal.open( {
                    templateUrl: 'partial.html',
                    controller: 'ctrl.modal'
                } );
            };

        }
    ] );

Thank you so much!

2

There are 2 answers

0
Andrew C. On BEST ANSWER

So this is super embarassing. Basically when I copied and pasted the modal controller out of the previous place where I had it, I forgot to delete the old (string named) controller. Angular was randomly choosing between the two identically named modal controllers when opening the modal, and giving me no warning that a controller of that name already existed. Whoops!

To those of you who are reading this answer, check to make sure you don't have any identically named controllers that would be causing a conflict. It's a likely result of any copy and paste error.

1
allienx On

Are you using ui-bootstrap? If you are, you have to inject $modal into your controller to use it.