I recently came across a sample demonstrating routing in AngularJS. I am curious about the connection between the dependency 'ngRoute'
and the module mainApp
, as shown in the syntax
var mainApp = angular.module("mainApp", ['ngRoute']);
.
In previous examples, I have only seen empty square brackets used in module declaration.
Here is the full code context:
var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/addStudent', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).
otherwise({
redirectTo: '/addStudent'
});
}]);