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.

1

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.