收到错误 [$injector:unpr] Unknown provider: $uibModalInstanceProvider

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

我有一个控制器 AddPrice,我使用 $uibModal.open 调用并传入控制器从价格列表屏幕作为弹出窗口调用它。 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) {

    }
}) ();

以上场景工作正常。

现在我想在不同的 ManagePrice.html 屏幕中重复使用 addPrice.html 作为 "in-page" 编辑而不是弹出窗口。

我在ManagePrice.html中添加了以下内容:

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

但我不断收到以下错误:

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

如何在这种情况下注入 $uibModalInstance?

这在 Angular JS 中是不允许的吗?

$uibModalInstance 对象是由 $uibModal 服务实例化的控制器的可注入对象。它不会注入到 $compile 服务实例化的控制器中。

来自文档:

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

有关详细信息,请参阅

如果这能帮助处于相同情况的其他人。最好的解决方案是将其作为指令。然后创建另一个模态指令来加载第一个指令。基本上会有 <edit-price><edit-price-modal> 指令限制为元素类型 ('E')