AngularJS错误:$ injector:unpr未知提供者 - $ modalInstanceProvider

时间:2016-04-20 18:16:21

标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap

我有一个你点击的按钮,它应该打开一个模态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>

2 个答案:

答案 0 :(得分:2)

使用$uibModalInstance代替$modalInstance

答案 1 :(得分:1)

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

同样在你的html中你放了ng-controller="Home"并在你的js文件中你将控制器声明为home所以你需要修复它以便名字匹配。