Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b04871b

Browse files
committed
docs(*): clarify limitations of app bootstrapping
- Note that bootstrapping on elements with transclusion directives is dangerous and not recommended. - group info on limitations, and add them to the guide Closes #11421 Closes #13572 Closes #12583
1 parent 4ba8e34 commit b04871b

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

docs/content/guide/bootstrap.ngdoc

+14-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ initialization.
5353

5454
Angular initializes automatically upon `DOMContentLoaded` event or when the `angular.js` script is
5555
evaluated if at that time `document.readyState` is set to `'complete'`. At this point Angular looks
56-
for the {@link ng.directive:ngApp `ng-app`} directive which designates your application root.
57-
If the {@link ng.directive:ngApp `ng-app`} directive is found then Angular will:
56+
for the {@link ng.directive:ngApp `ngApp`} directive which designates your application root.
57+
If the {@link ng.directive:ngApp `ngApp`} directive is found then Angular will:
5858

5959
* load the {@link guide/module module} associated with the directive.
6060
* create the application {@link auto.$injector injector}
6161
* compile the DOM treating the {@link ng.directive:ngApp
62-
`ng-app`} directive as the root of the compilation. This allows you to tell it to treat only a
62+
`ngApp`} directive as the root of the compilation. This allows you to tell it to treat only a
6363
portion of the DOM as an Angular application.
6464

6565

@@ -142,6 +142,17 @@ This is the sequence that your code should follow:
142142
2. Call {@link angular.bootstrap} to {@link compiler compile} the element into an
143143
executable, bi-directionally bound application.
144144

145+
## Things to keep in mind
146+
147+
There a few things to keep in mind regardless of automatic or manual bootstrapping:
148+
149+
- While it's possible to bootstrap more than one AngularJS application per page, we don't actively
150+
test against this scenario. It's possible that you'll run into problems, especially with complex apps, so
151+
caution is advised.
152+
- Do not bootstrap your app on an element with a directive that uses {@link ng.$compile#transclusion transclusion}, such as
153+
{@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
154+
Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
155+
causing animations to stop working and making the injector inaccessible from outside the app.
145156

146157
## Deferred Bootstrap
147158

src/Angular.js

+24-8
Original file line numberDiff line numberDiff line change
@@ -1402,10 +1402,17 @@ function getNgAttribute(element, ngAttr) {
14021402
* designates the **root element** of the application and is typically placed near the root element
14031403
* of the page - e.g. on the `<body>` or `<html>` tags.
14041404
*
1405-
* Only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
1406-
* found in the document will be used to define the root element to auto-bootstrap as an
1407-
* application. To run multiple applications in an HTML document you must manually bootstrap them using
1408-
* {@link angular.bootstrap} instead. AngularJS applications cannot be nested within each other.
1405+
* There are a few things to keep in mind when using `ngApp`:
1406+
* - only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
1407+
* found in the document will be used to define the root element to auto-bootstrap as an
1408+
* application. To run multiple applications in an HTML document you must manually bootstrap them using
1409+
* {@link angular.bootstrap} instead.
1410+
* - AngularJS applications cannot be nested within each other.
1411+
* - Do not use a directive that uses {@link ng.$compile#transclusion transclusion} on the same element as `ngApp`.
1412+
* This includes directives such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and
1413+
* {@link ngRoute.ngView `ngView`}.
1414+
* Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
1415+
* causing animations to stop working and making the injector inaccessible from outside the app.
14091416
*
14101417
* You can specify an **AngularJS module** to be used as the root module for the application. This
14111418
* module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
@@ -1545,16 +1552,25 @@ function angularInit(element, bootstrap) {
15451552
* @description
15461553
* Use this function to manually start up angular application.
15471554
*
1548-
* See: {@link guide/bootstrap Bootstrap}
1549-
*
1550-
* Note that Protractor based end-to-end tests cannot use this function to bootstrap manually.
1551-
* They must use {@link ng.directive:ngApp ngApp}.
1555+
* For more information, see the {@link guide/bootstrap Bootstrap guide}.
15521556
*
15531557
* Angular will detect if it has been loaded into the browser more than once and only allow the
15541558
* first loaded script to be bootstrapped and will report a warning to the browser console for
15551559
* each of the subsequent scripts. This prevents strange results in applications, where otherwise
15561560
* multiple instances of Angular try to work on the DOM.
15571561
*
1562+
* <div class="alert alert-warning">
1563+
* **Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
1564+
* They must use {@link ng.directive:ngApp ngApp}.
1565+
* </div>
1566+
*
1567+
* <div class="alert alert-warning">
1568+
* **Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
1569+
* such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
1570+
* Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
1571+
* causing animations to stop working and making the injector inaccessible from outside the app.
1572+
* </div>
1573+
*
15581574
* ```html
15591575
* <!doctype html>
15601576
* <html>

0 commit comments

Comments
 (0)