diff options
| author | Joscha Feth | 2013-11-28 14:33:03 +0100 | 
|---|---|---|
| committer | Peter Bacon Darwin | 2013-12-09 16:32:09 +0000 | 
| commit | b4d44e12987131bfd23399947fe9b2f860cc5729 (patch) | |
| tree | f21bbfce5e19fe47e042570c656d9d3bf7f28a0e | |
| parent | ca116c35a63e06e62337ce9713a55d28ad9ebce8 (diff) | |
| download | angular.js-b4d44e12987131bfd23399947fe9b2f860cc5729.tar.bz2 | |
docs($injector): add example on how to use the element.injector
Closes #5188
| -rw-r--r-- | src/auto/injector.js | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/src/auto/injector.js b/src/auto/injector.js index ab6c1f96..ee1d475c 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -27,6 +27,28 @@   *     $rootScope.$digest();   *   });   * </pre> + *  + * Sometimes you want to get access to the injector of a currently running Angular app + * from outside Angular. Perhaps, you want to inject and compile some markup after the + * application has been bootstrapped. You can do this using extra `injector()` added + * to JQuery/jqLite elements. See {@link angular.element}. + *  + * *This is fairly rare but could be the case if a third party library is injecting the + * markup.* + *  + * In the following example a new block of HTML containing a `ng-controller` + * directive is added to the end of the document body by JQuery. We then compile and link + * it into the current AngularJS scope. + *  + * <pre> + * var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>'); + * $(document.body).append($div); + *  + * angular.element(document).injector().invoke(function($compile) { + *   var scope = angular.element($div).scope(); + *   $compile($div)(scope); + * }); + * </pre>   */ | 
