I've been investigating the tutorial example from AngularJs's site ( this one)
(The main html is pretty empty (except for ng-view and ng-app=phonecatApp))
The app.js file includes this :
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers',
'phonecatFilters',
'phonecatServices'
]);
phonecatApp.config(['$routeProvider',...
Ok, so we have phonecatApp module with many dependencies.
But then I saw the controller.js file ( they opened a new module for the controllers)
/*1*/ var phonecatControllers = angular.module('phonecatControllers', []);
/*2*/
/*3*/ phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'Phone',
/*4*/ function($scope, $routeParams, Phone) {
/*5*/ ...
/*6*/ });
/*7*/
/*8*/ }]);
Phone is a service. ( which is on another module , different js file)
Question
In line #3 , how does it know what is the Phone parameter ? they didnt add any dependecy module in line #1 !
Same for the $routeParams , how does it know it ? they didn't add any dependency in line #1 to the ngRoute !
Am I missing something here ?
Phonelook like? Is this service registered tophoncatControllersmodule? If not, it does seem strange.phonecatControllerswill always be registered as a dependency withphonecatServices. Not a great assumption to make when creating independent modules for reuse. Since, there is only a single$injectorin the app, this works, but I wouldn't say it is a great way to split modules.