Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Unified Diff: third_party/pkg/angular/lib/directive/ng_include.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/directive/ng_include.dart
diff --git a/third_party/pkg/angular/lib/directive/ng_include.dart b/third_party/pkg/angular/lib/directive/ng_include.dart
new file mode 100644
index 0000000000000000000000000000000000000000..62e8dd2934ef1b7daf3bcf2ef4e9795519a1f4c7
--- /dev/null
+++ b/third_party/pkg/angular/lib/directive/ng_include.dart
@@ -0,0 +1,61 @@
+part of angular.directive;
+
+/**
+ * Fetches, compiles and includes an external Angular template/HTML.
+ *
+ * A new child [Scope] is created for the included DOM subtree.
+ *
+ * [NgIncludeDirective] provides only one small part of the power of
+ * [NgComponent].  Consider using directives and components instead as they
+ * provide this feature as well as much more.
+ *
+ * Note: The browser's Same Origin Policy (<http://v.gd/5LE5CA>) and
+ * Cross-Origin Resource Sharing (CORS) policy (<http://v.gd/nXoY8y>) restrict
+ * whether the template is successfully loaded.  For example,
+ * [NgIncludeDirective] won't work for cross-domain requests on all browsers and
+ * for `file://` access on some browsers.
+ */
+@NgDirective(
+ selector: '[ng-include]',
+ map: const {'ng-include': '@url'} )
+class NgIncludeDirective {
+
+ dom.Element element;
+ Scope scope;
+ BlockCache blockCache;
+ Injector injector;
+
+ Block _previousBlock;
+ Scope _previousScope;
+
+ NgIncludeDirective(this.element, this.scope, this.blockCache, this.injector);
+
+ _cleanUp() {
+ if (_previousBlock == null) {
+ return;
+ }
+
+ _previousBlock.remove();
+ _previousScope.$destroy();
+ element.innerHtml = '';
+
+ _previousBlock = null;
+ _previousScope = null;
+ }
+
+ _updateContent(createBlock) {
+ // create a new scope
+ _previousScope = scope.$new();
+ _previousBlock = createBlock(injector.createChild([new Module()..value(Scope, _previousScope)]));
+
+ _previousBlock.elements.forEach((elm) => element.append(elm));
+ }
+
+
+ set url(value) {
+ _cleanUp();
+ if (value != null && value != '') {
+ blockCache.fromUrl(value).then(_updateContent);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698