2015-06-06 35 views
0

我使用angular-modal-service在我的yeoman generated angular application中顯示模態。我正在關注文檔,但在通過inputs參數傳遞數據時出現此錯誤。爲什麼在將數據傳遞給模態控制器時會收到角度模態服務錯誤?

Error: [$injector:unpr] Unknown provider: userProvider <- user <- targetModalCtrl

這是模態被觸發

'use strict'; 

angular.module('webClientApp') 
    .controller('LogCreateCtrl', function ($scope, $rootScope, $log, $http, config, ModalService, $route) { 

    /*-- OTHER FUNCTIONS --*/  

    // record time in 
    $scope.recordTimeIn = function() { 
    // show target modal 
    ModalService.showModal({ 
     templateUrl: "views/targetModal.html", 
     controller: "targetModalCtrl", 
     inputs: { 
     user: $scope.user.id 
     } 
    }).then(function(modal) { 
     modal.element.modal(); 
     modal.close.then(function(result) { 
     $log.debug(result); 
     }); 
    }); 
    } 
}); 

在控制器的功能,這是模態控制器:

'use strict'; 

angular.module('webClientApp') 
    .controller('targetModalCtrl', ['$scope', 'user', function($scope, user) { 
    $log.debug(user); 
}]); 

,將模態,如果我不使用罰款展示LogCreateCtrl中的inputs參數,並刪除targetModalCtrl中的user

+0

這是什麼用戶。工廠還是服務? –

+1

你可以請同樣的朋友分享一下嗎? – nikhil

+0

@BharatBhushan它是來自控制器的模式觸發的數據。 –

回答

0

我不熟悉angular-modal-service但我看到兩個潛在的問題...

  1. 我不知道的模式服務是否足夠強大,通過數組符號來處理注射(the docs麥凱納牛逼清楚這個)
  2. 我沒有看到控制器的參數

$log你可以嘗試改變你的控制器以下...

angular.module('webClientApp') 
    .controller('targetModalCtrl', function($scope, $log, user) { 
    $log.debug(user); 
}); 
+0

哦,是的,謝謝我忘記包括$日誌,但我試過了,但問題仍然存在。在這個[示例](https://github.com/dwmkerr/angular-modal-service/blob/master/samples/complex/complexcontroller.js)中,它使用了數組注入。任何線索爲什麼會發生這種情況? –

0

我看到案例導致問題的問題。

在輸入中,用戶的值是$ scope.user.id,現在在控制器中,我無法看到,user.id在範圍內的任何地方設置,這將意味着未定義的值分配給用戶。

Modal服務會刪除未定義的值,因此無法注入用戶。

+0

對不起,我沒有把完整的代碼。 '$ scope.user.id'已經用一個前面的值聲明瞭。但是,即使我將輸入值從'$ scope.user.id'更改爲隨機字符串(例如:'test'),它仍會給出錯誤。 –

+1

okies。如果你分享一個蹦牀,這將是非常棒的。 – nikhil

相關問題