2015-11-08 37 views
2

我有AngularJS應用程序(版本1.4.7)和最新版本的ui.bootstrap。當我嘗試注入$ uibModalInstance會拋出錯誤出現問題Unknown provider: $uibModalInstanceProviderAngularJS ui-bootstrap模態實例問題

這裏是控制器代碼:

/** 
* @constructor 
* @param $uibModal 
*/ 
function ClientsController($uibModal) 
{ 
    var _this = this; 

    _this.$uibModal = $uibModal; 
} 


/** 
* 
*/ 
ClientsController.prototype.create = function() 
{ 
    var instance = this.$uibModal.open(
     { 
      animation: true, 
      templateUrl: 'modules/clients/views/modal/client.html', 
      controller: 'ClientModalInstController as ctrl', 
      size: 'lg' 
     } 
    ); 
}; 

這裏是模態控制器

ClientModalInstController.$inject = [ 
    '$uibModalInstance' 
]; 


/** 
* @constructor 
* @param $uibModalInstance 
*/ 
function ClientModalInstController($uibModalInstance) 
{ 
    var _this = this; 

    _this.$uibModalInstance = $uibModalInstance; 
} 

任何想法可能是什麼造成這種行爲的?

+0

你在哪裏註冊'ClientModalInstController'作爲控制器? – Phil

+0

該代碼是$注入塊以上,我只是沒有顯示在這裏 – SilvioMarijic

+0

似乎工作很好,在這裏〜http://plnkr.co/edit/Z3UNct38ZGCsvMHTZ4M6?p=preview。一定是你錯過的東西。你的模塊的依賴是什麼? – Phil

回答

0

什麼引起的行爲如下:

$uibModal.open()返回$modalInstance這需要依賴注入的$uibModalInstanceClientModalInstController控制器。我看不到代碼爲ClientModalInstController,但它需要有$uibModalInstance注入到它,這比$uibModal

不同,您可以看到在模態例如在用戶界面的自舉文檔的JavaScript選項卡這樣的例子:http://angular-ui.github.io/bootstrap/

向下滾動到文檔的Modal部分,查看ModalInstanceCtrl及其注入依賴關係的Javascript選項卡中的代碼。

+1

我有$ uibModalInstance注入,那就是它拋出錯誤的部分 – SilvioMarijic

+0

我貼了模態控制器代碼 – SilvioMarijic

+0

$ uibModalInstance已經被注入,只有注入拋出錯誤。 – Vivek

0

@SilvioMarijic這打破了,如果項目沒有注入正確的順序。確保一切排隊。

代碼示例:

angular.module('App').controller('YourController', ['$scope', '$http', '$uibModal', 
function ($scope, $http, $uibModal) { 

    //CODE HERE 

}]); 

假設你在構造函數(或線)替換$ http和$ uiModal你會得到你的描述錯誤。