2016-05-13 228 views
0

聲明聲明服務訪問服務內部控制器

calculator_app.service('FullPath', function() { 
    this.full_path = function (pt, pg, prt, cd,scpe) { 

-- some logic--- 
};}); 

控制器

calculator_app.controller("Opportunity_Controller", ['$scope', '$http', 'ngDialog', 'FullPath', 'FillOpportunity', function ($scope, FullPath, FillOpportunity, $http, ngDialog) { 

     $scope.find_path = function() { 
      $scope.result_path = FullPath.full_path($scope.res_pt, $scope.res_pg, $scope.res_prt, $scope.res_cd, $scope); 
}]); 

線FullPath.full_path拋出誤差FULLPATH未定義....

回答

0

依賴關係順序應與DI陣列注入的方式相同,基本上在注入依賴序列時有不匹配。

calculator_app.controller("Opportunity_Controller", ['$scope', '$http', 'ngDialog', 'FullPath', 'FillOpportunity', 
    //corrected sequence of dependencies below 
    function ($scope, $http, ngDialog, FullPath, FillOpportunity) { 
+0

謝謝。解決了。但是,我無法訪問ngDialog。 ngDialog is undefined wen我做了console.log $ scope.calculate_opportunity = function(ngDialog){ ngDialog.open({template:'

I am Ng Dialog

'}); } }]); –

+0

我還沒有完全按照答案中的建議更改代碼 –