↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Define multiple Angular apps in one page

The page explains that AngularJS auto-bootstrap via ng-app works only once per HTML document, so if a page has multiple ng-app attributes, only the first one is initialized. It then shows ways to place two Angular apps on the same page by bootstrapping them manually or by using a root app that includes both modules.

Reading notes
#

  • Only one AngularJS application can be auto-bootstrapped per HTML document.
  • If a page has multiple ng-app attributes, only the first one is considered and the rest are ignored.
  • One option is to remove ng-app and bootstrap both apps manually with angular.bootstrap().
  • Another option is to keep ng-app for the first app and manually bootstrap only the second app.
  • A third option is to define a root app with ng-app and inject both apps as modules in that root app.