diff --git a/modules/angular2/src/core/compiler/directive_metadata_reader.js b/modules/angular2/src/core/compiler/directive_metadata_reader.js index 8d599d627b..5771c2da6f 100644 --- a/modules/angular2/src/core/compiler/directive_metadata_reader.js +++ b/modules/angular2/src/core/compiler/directive_metadata_reader.js @@ -30,6 +30,21 @@ export class DirectiveMetadataReader { componentDirectivesMetadata(annotation:Component):List { var template = annotation.template; - return isPresent(template) && isPresent(template.directives) ? template.directives : []; + var result:List = ListWrapper.create(); + if (isPresent(template) && isPresent(template.directives)) { + this._buildList(result, template.directives); + } + return result; + } + + _buildList(out:List, tree:List) { + for (var i = 0; i < tree.length; i++) { + var item = tree[i]; + if (ListWrapper.isList(item)) { + this._buildList(out, item); + } else { + ListWrapper.push(out, item); + } + } } } diff --git a/modules/angular2/test/core/compiler/directive_metadata_reader_spec.js b/modules/angular2/test/core/compiler/directive_metadata_reader_spec.js index 714d5ea376..a34b7bbb12 100644 --- a/modules/angular2/test/core/compiler/directive_metadata_reader_spec.js +++ b/modules/angular2/test/core/compiler/directive_metadata_reader_spec.js @@ -5,6 +5,7 @@ import {TemplateConfig} from 'angular2/src/core/annotations/template_config'; import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata'; import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy'; import {CONST} from 'angular2/src/facade/lang'; +import {If, Foreach} from 'angular2/directives'; @Decorator({ @@ -29,7 +30,13 @@ class ComponentWithoutDirectives {} }) class ComponentWithDirectives {} - +@Component({ + selector: 'withDirectivesTree', + template: new TemplateConfig({ + directives: [[SomeDirective, [Foreach, If]], ComponentWithoutDirectives] + }) +}) +class ComponentWithDirectivesTree {} export function main() { describe("DirectiveMetadataReader", () => { @@ -61,6 +68,11 @@ export function main() { var cmp = reader.read(ComponentWithDirectives); expect(cmp.componentDirectives).toEqual([ComponentWithoutDirectives]); }); + + it("should return a list of directives specified in the template config as a tree", () => { + var cmp = reader.read(ComponentWithDirectivesTree); + expect(cmp.componentDirectives).toEqual([SomeDirective, Foreach, If, ComponentWithoutDirectives]); + }); }); }); } diff --git a/modules/angular2/test/core/compiler/integration_spec.js b/modules/angular2/test/core/compiler/integration_spec.js index 9be81b64e1..1695bdf00b 100644 --- a/modules/angular2/test/core/compiler/integration_spec.js +++ b/modules/angular2/test/core/compiler/integration_spec.js @@ -262,7 +262,7 @@ class PushBasedComp { @Component({ template: new TemplateConfig({ - directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp] + directives: [MyDir, [[ChildComp], SomeTemplate, PushBasedComp]] }) }) class MyComp { @@ -305,4 +305,3 @@ class MyService { this.greeting = 'hello'; } } -