Can't find method in Angular Service

0

I have written a basic angular JS controller and service to inject in, code as follows.

Controller

app.controller("SEFlexHomeController", ["$scope", "$http", "$modal", "$log", "$element", "JobService", "$rootScope", "SEApplicationService", function ($scope, $http, $modal, $log, $element, $rootScope, SEApplicationService) {
        $scope.isDataLoading = false;
        $scope.configvalues = SEApplicationService.getCloudConfigParams();
    }
]);

Service

app.factory("SEApplicationService", ["$log", "$http", "$timeout", function($log, $http, $timeout) {

    var appService = {};    

    appService.getCloudConfigParams = function () {
        return $http.post("/SEFlex/SEFlexAdmin/GetCloudConfigValues");
    }

    return appService;
}]);

And as far as I can understand, this should work. However in the console I can see the error

Exception was thrown at line 5, column 9 in http://localhost:58270/app/SEFlex/controllers/SEFlexHomeController.js 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'getCloudConfigParams'

I assume I'm doing something basic wrong but I can't see what. Can anyone spot the issue?

javascript
asp.net
angularjs
asp.net-mvc
asked on Stack Overflow Oct 8, 2015 by NZJames

2 Answers

2

You forgot to inject one service (JobService):

app.controller("SEFlexHomeController", ["$scope", "$http", "$modal", "$log", "$element", "JobService", "$rootScope", "SEApplicationService", function ($scope, $http, $modal, $log, $element, JobService, $rootScope, SEApplicationService) {

You have the inline typehint but not the param injected in the controller function.

answered on Stack Overflow Oct 8, 2015 by taxicala
2

you have missed out injecting JobService proerly. correction -

app.controller("SEFlexHomeController", ["$scope", "$http", "$modal", "$log", "$element", "JobService", "$rootScope", "SEApplicationService", function ($scope, $http, $modal, $log, $element, JobService, $rootScope, SEApplicationService) {
        $scope.isDataLoading = false;
        $scope.configvalues = SEApplicationService.getCloudConfigParams();
    }
]);
answered on Stack Overflow Oct 8, 2015 by Rabi

User contributions licensed under CC BY-SA 3.0