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

Commit b4d44e1

Browse files
joschapetebacondarwin
authored andcommitted
docs($injector): add example on how to use the element.injector
Closes angular#5188
1 parent ca116c3 commit b4d44e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/auto/injector.js

+22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@
2727
* $rootScope.$digest();
2828
* });
2929
* </pre>
30+
*
31+
* Sometimes you want to get access to the injector of a currently running Angular app
32+
* from outside Angular. Perhaps, you want to inject and compile some markup after the
33+
* application has been bootstrapped. You can do this using extra `injector()` added
34+
* to JQuery/jqLite elements. See {@link angular.element}.
35+
*
36+
* *This is fairly rare but could be the case if a third party library is injecting the
37+
* markup.*
38+
*
39+
* In the following example a new block of HTML containing a `ng-controller`
40+
* directive is added to the end of the document body by JQuery. We then compile and link
41+
* it into the current AngularJS scope.
42+
*
43+
* <pre>
44+
* var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>');
45+
* $(document.body).append($div);
46+
*
47+
* angular.element(document).injector().invoke(function($compile) {
48+
* var scope = angular.element($div).scope();
49+
* $compile($div)(scope);
50+
* });
51+
* </pre>
3052
*/
3153

3254

0 commit comments

Comments
 (0)