Recently, I've been diving into AngularJS and came across an interesting issue. It seems that when I include $RouteParams
in the injection of my AngularJS service using .service
, but don't actually utilize $RouteParams
, the service ceases to work properly.
myApp.service('myService', function() {
this.name = 'myServiceName';
var self = this;
this.nameLength = function () {
return self.name.length;
};
});
myApp.controller('mainController', ['$scope','$log','$routeParams','myService',function($scope, $log,myService,$routeParams) {
$scope.handle = myService.name;
}]);
I find it odd that only when I make use of $RouteParams
in the controller does everything function correctly. Could someone shed some light on why $RouteParams
has an impact on the behavior of the .service
?