7
How many ng-App attributes can be declared in in Angular JS? and under what circumstances? 

As I know that ng-app is used for auto bootstrap for an Angular JS application.

Syed
  • 2,471
  • 10
  • 49
  • 89
  • possible duplicate of [Multiple ng-app directives on a page](http://stackoverflow.com/questions/19666816/multiple-ng-app-directives-on-a-page) – Stewie Jan 13 '14 at 11:29

2 Answers2

11

http://docs.angularjs.org/api/ng.directive:ngApp

Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead. AngularJS applications cannot be nested within each other.

TL; DR: you can have more than one, but only the first will be bootstrapped.

This question is similar to:

Community
  • 1
  • 1
mustafa.0x
  • 1,476
  • 2
  • 17
  • 30
1

Came across very interesting virtue of ng-app directive for angularjs version 1.2.x, we can have applications bootstrapped without specifying any module name.

By using <html ng-app=""> in the HTML template & a script file that contains the controller as a function:

function TestController($scope) {
    $scope.customer = {
      name: 'Naomi',
      address: '1600 Amphitheatre'
    };
    $scope.cars = ['Audi', 'BMW', 'Merc'];
  }

Demo link

bummi
  • 27,123
  • 14
  • 62
  • 101
Abhijeet
  • 8,561
  • 5
  • 70
  • 76