I've encountered an issue while attempting to utilize a service for managing an http request:
angular
.module('app')
.factory('stats', function($http){
return {
getStats: function(path) {
return $http
.get(path)
.then(function(result) {
//resolving the promise with data
return result.data;
});
}
};
});
However, when I invoke the getStats method in the controller, the $routeParams property turns out to be undefined, leading to the request not executing as expected:
app.controller('ChartController', ['$route', 'stats', '$scope', '$rootScope', '$routeParams', function($route, stats, $scope, $rootScope, $routeParams) {
console.log($routeParams);
var path = "/players/players/" + $routeParams.playerId;
var players = stats.getStats(path);
This error doesn't occur when I directly make the http request within the controller instead of utilizing a service.