How many ng applications can be declared in Angular JS?

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

As I know, ng-app is used to load automatically for an Angular JS application.

+7
angularjs
source share
2 answers

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

Only one AngularJS application can be automatically loaded into an HTML document. The first ngApp found in the document will be used to determine the root element for automatic loading as an application. To run multiple applications in an HTML document, you must manually download them using angular.bootstrap. AngularJS applications cannot be nested.

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

This question is similar to:

  • How to define two angular applications / modules on one page?
  • Multiple ng-app directives per page
  • AngularJS Multiple ng apps per page
+11
source share

Enjoying the very interesting advantage of the ng-app directive for angularjs version 1.2.x, we can run applications without specifying a module name.

Using <html ng-app=""> in the HTML template and 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

+1
source share

All Articles