Sharath
Sharath

Reputation: 606

Getting the error [$injector:unpr] Unknown provider: $uibModalInstanceProvider

I have a controller AddPrice which I call from a Price listing screen as a popup using the $uibModal.open call and passing in the controller. Controller is not defined in the addPrice.html

addPrice.html

<div>
  <form>
    <!-- contains UI controls but controller is not mentioned in this page -->
  </form>
</div>

addPriceController.js


(function () {
    'use strict';

    var controllerId = 'addPriceController';

    angular.module('myApp').controller(controllerId, [
      '$scope',
      '$q',
      '$uibModalInstance',
      addPriceController]);

    function addPriceController(
        $scope,
        $q, 
        modalInstance) {

    }
}) ();

The above scenario works fine.

Now I want to reuse addPrice.html in a different ManagePrice.html screen as an "in-page" edit and NOT as a pop up.

I added the following in ManagePrice.html:

<div ng-include src="'addPrice.html'"
     ng-controller="addPriceController">

But I keep getting following error:

angular.js:15018 Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- addPriceController

How can I inject $uibModalInstance in this scenario?

OR

Is this not allowed in Angular JS?

Upvotes: 0

Views: 945

Answers (2)

Sharath
Sharath

Reputation: 606

In case this helps others in same kind of situation. The best solution would be to make this a directive. Then make another modal directive which would load the first directive. Basically there would be a <edit-price> and <edit-price-modal> directives restricted to element type ('E')

Upvotes: 0

georgeawg
georgeawg

Reputation: 48968

The $uibModalInstance object is an injectable of controllers instantiated by the $uibModal service. It is not injected in controllers instantiated by the $compile service.

From the DOCs:

$uibModal's open function

options parameter

  • controller (Type: function|string|array, Example: MyModalController) - A controller for the modal instance, either a controller name as a string, or an inline controller function, optionally wrapped in array notation for dependency injection. Allows the controller-as syntax. Has a special $uibModalInstance injectable to access the modal instance.

For more information, see

Upvotes: 1

Related Questions