I'm splitting my angular code in different modules and I'm facing an issue. I suppose I don't understand the internals of services injection.
going from controllers defined as global functions
angular.module('foo', []);
function fooCtrl($scope, $routeParams) {
to a declarative form in order to have them as part of a module
angular.module('foo',[]).
controller(['fooCtrl', function($scope, $routeParams) {
in the end I lose the $routeParams service (undefined). Do I need to inject explicitly my $routeParams to the module? How do I do it?
It appears like you are not calling your controller() correctly.
angular.module('foo',[]).
controller("fooCtrl", <-- controller name
['$scope', '$routeParams', <-- list of dependencies
function($scope, $routeParams) { <--actual controller function
alert($routeParams);
}]);
Example on jsfiddle
If you don't plan on doing minification you can also do the following:
angular.module('foo',[]).controller("fooCtrl", function($scope, $routeParams) {
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With