I'm working on an angular project, where I'm adding new functionality to an older project.
I'm trying to register a service with my controller but getting an error where my controller is unable to find the functions in the service.
Here's how my controller is defined (I know it's not the standard way, but I have to follow this because the entire application does.)
angular.module("test").controller("listCtrl", listCtrl);
listCtrl.$inject = ["$scope", "$state", "$timeout", "listService", "$rootScope"];
function listCtrl($scope, $state, $timeout, listService, $rootScope ) {
this.$scope= $scope;
$scope.service=listService;
//some other definitions
$scope.items = $scope.service.getPage(%function_ARGUMENTS%);
}
Here's how the service is defined:
angular.module("test").service("listService", listService);
listService.$inject = ['$state', '$rootScope'];
function listService($state, $rootScope) {
function getPage(%function_ARGUMENTS%) {
//getPage function definition goes here
}
}
Now, for some reason, I get the error:
Cannot read property 'getPage' of undefined
I cannot figure out what might be causing this.
Is the problem with how $scope is defined? If yes, then what would be the correct way to do this, assuming this.$scope=$scope cannot be modified.
EDIT: Fixed the plural typo in the question. I do not have that typo in my program, it was a mistake I made while typing on SO.
$scope.services.getPage(%function_ARGUMENTS%);it must be$scope.service.getPage(%function_ARGUMENTS%);