| OLD | NEW |
| (Empty) | |
| 1 part of angular.directive; |
| 2 |
| 3 /** |
| 4 * Fetches, compiles and includes an external Angular template/HTML. |
| 5 * |
| 6 * A new child [Scope] is created for the included DOM subtree. |
| 7 * |
| 8 * [NgIncludeDirective] provides only one small part of the power of |
| 9 * [NgComponent]. Consider using directives and components instead as they |
| 10 * provide this feature as well as much more. |
| 11 * |
| 12 * Note: The browser's Same Origin Policy (<http://v.gd/5LE5CA>) and |
| 13 * Cross-Origin Resource Sharing (CORS) policy (<http://v.gd/nXoY8y>) restrict |
| 14 * whether the template is successfully loaded. For example, |
| 15 * [NgIncludeDirective] won't work for cross-domain requests on all browsers and |
| 16 * for `file://` access on some browsers. |
| 17 */ |
| 18 @NgDirective( |
| 19 selector: '[ng-include]', |
| 20 map: const {'ng-include': '@url'} ) |
| 21 class NgIncludeDirective { |
| 22 |
| 23 dom.Element element; |
| 24 Scope scope; |
| 25 BlockCache blockCache; |
| 26 Injector injector; |
| 27 |
| 28 Block _previousBlock; |
| 29 Scope _previousScope; |
| 30 |
| 31 NgIncludeDirective(this.element, this.scope, this.blockCache, this.injector); |
| 32 |
| 33 _cleanUp() { |
| 34 if (_previousBlock == null) { |
| 35 return; |
| 36 } |
| 37 |
| 38 _previousBlock.remove(); |
| 39 _previousScope.$destroy(); |
| 40 element.innerHtml = ''; |
| 41 |
| 42 _previousBlock = null; |
| 43 _previousScope = null; |
| 44 } |
| 45 |
| 46 _updateContent(createBlock) { |
| 47 // create a new scope |
| 48 _previousScope = scope.$new(); |
| 49 _previousBlock = createBlock(injector.createChild([new Module()..value(Scope
, _previousScope)])); |
| 50 |
| 51 _previousBlock.elements.forEach((elm) => element.append(elm)); |
| 52 } |
| 53 |
| 54 |
| 55 set url(value) { |
| 56 _cleanUp(); |
| 57 if (value != null && value != '') { |
| 58 blockCache.fromUrl(value).then(_updateContent); |
| 59 } |
| 60 } |
| 61 } |
| OLD | NEW |