控制器内的访问服务

时间:2016-05-13 19:59:16

标签: angularjs

宣布服务

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未定义....

1 个答案:

答案 0 :(得分:0)

依赖顺序应该是相同的,你在DI数组中注入的方式,基本上你在依赖序列的注入方面不匹配。

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