AngularJS Error: $injector:unpr Unknown Provider - $modalInstanceProvider

AngularJS Error: $injector:unpr Unknown Provider - $modalInstanceProvider

我有一个按钮,您可以单击它,它应该会打开模式 onclick。但是,当我单击该按钮时,出现错误 "Unknown provider: $modalInstanceProvider <- $modalInstance"。到目前为止我检查了一切。我错过了什么?这是到目前为止的代码。

应用程序。 js - 加载 ui-bootstrap.

var app = angular.module('myApp', ['ngRoute', 'ui.bootstrap']);

services.js - 这是模态服务。

app.factory('modalService',['$uibModal', function($uibModal){
return {
  openMenuModal: function(index, title, description) {
    var modalObj = $uibModal.open({
      templateUrl: 'partials/modal.html',
      backdrop: 'static',
      keyboard: true,
      size: 'sm',
      controller: function($scope, $modalInstance){
        $scope.title = title;
        $scope.description = description;

        $scope.ok = function(id){
          $modalInstance.close(); 
        }
        $scope.cancel = function(){
          $modalInstance.dismiss('cancel');
        }
       }
    });
  }
};
}]);

家庭控制器

app.controller('home', [
'$scope', 
'contentService', 
'$http',
'$uibModal', 
'modalService', function($scope, contentService, $http, $uibModal, modalService){

contentService.then(function(data){
    $scope.data = data;
    $scope.shortcutList = $scope.data.shortcuts;  // list of shortcuts
    $scope.name = $scope.data.user;               // user's name
    $scope.userThumb = $scope.data.userThumb;     // user thumbnail image


    $scope.deleteBox = function(index, title, description){
        modalService.openMenuModal('t', title, description);
    };
});

}]);

模态模板

<div ng-controller="Home">
  <div class="modalBox animated fadeIn">
    <h1> {{title}} </h1>
        <p>{{description}}</p>
        <div class="modal-footer"></div>    
 </div>
 </div>

快捷方式模板按钮 - 这是我要调用 deleteBox() 的地方

<button class="btn btn-primary deleteBox" ng-click="deleteBox($index,  'Are You sure you want to delete this?', 'description text')"></button>

使用$uibModalInstance代替$modalInstance

您应该使用 $uibModalInstance 而不是 $modalInstance。

另外,在您的 html 中,您放置了 ng-controller="Home",并且在您的 js 文件中,您将控制器声明为 home,因此您需要修复此问题,以便名称匹配。