Defining the AngularJS Application Root Element

The next step is to define the ng-app parameter in the root element so that AngularJS knows where to begin compiling the application. You should also define the module in your JavaScript code to provide a namespace to use when adding controllers, filters, and services.

Line 2 of Listing 2.1 defines the DOM root for an AngularJS module. Notice that ng-app is assigned the module name firstApp, which corresponds to the module in the JavaScript code:

02 <html ng-app="firstApp">

Line 1 in Listing 2.2 shows the firstApp module object being created in the JavaScript code:

01 var firstApp = angular.module('firstApp', []);

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.