2016-05-13 198 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

我还没有完全按照答案中的建议更改代码 –