Skip to content

Commit 6d8ccaa

Browse files
committed
feat(TemplateConfig): support array of arrays in TemplateConfig directives
Fixes angular#592 Closes angular#600
1 parent 8844671 commit 6d8ccaa

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

modules/angular2/src/core/compiler/directive_metadata_reader.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ export class DirectiveMetadataReader {
3030

3131
componentDirectivesMetadata(annotation:Component):List<Type> {
3232
var template = annotation.template;
33-
return isPresent(template) && isPresent(template.directives) ? template.directives : [];
33+
var result:List<Type> = ListWrapper.create();
34+
if (isPresent(template) && isPresent(template.directives)) {
35+
this._buildList(result, template.directives);
36+
}
37+
return result;
38+
}
39+
40+
_buildList(out:List<Type>, tree:List<any>) {
41+
for (var i = 0; i < tree.length; i++) {
42+
var item = tree[i];
43+
if (ListWrapper.isList(item)) {
44+
this._buildList(out, item);
45+
} else {
46+
ListWrapper.push(out, item);
47+
}
48+
}
3449
}
3550
}

modules/angular2/test/core/compiler/directive_metadata_reader_spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {TemplateConfig} from 'angular2/src/core/annotations/template_config';
55
import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata';
66
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
77
import {CONST} from 'angular2/src/facade/lang';
8+
import {If, Foreach} from 'angular2/directives';
89

910

1011
@Decorator({
@@ -29,7 +30,13 @@ class ComponentWithoutDirectives {}
2930
})
3031
class ComponentWithDirectives {}
3132

32-
33+
@Component({
34+
selector: 'withDirectivesTree',
35+
template: new TemplateConfig({
36+
directives: [[SomeDirective, [Foreach, If]], ComponentWithoutDirectives]
37+
})
38+
})
39+
class ComponentWithDirectivesTree {}
3340

3441
export function main() {
3542
describe("DirectiveMetadataReader", () => {
@@ -61,6 +68,11 @@ export function main() {
6168
var cmp = reader.read(ComponentWithDirectives);
6269
expect(cmp.componentDirectives).toEqual([ComponentWithoutDirectives]);
6370
});
71+
72+
it("should return a list of directives specified in the template config as a tree", () => {
73+
var cmp = reader.read(ComponentWithDirectivesTree);
74+
expect(cmp.componentDirectives).toEqual([SomeDirective, Foreach, If, ComponentWithoutDirectives]);
75+
});
6476
});
6577
});
6678
}

modules/angular2/test/core/compiler/integration_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class PushBasedComp {
262262

263263
@Component({
264264
template: new TemplateConfig({
265-
directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp]
265+
directives: [MyDir, [[ChildComp], SomeTemplate, PushBasedComp]]
266266
})
267267
})
268268
class MyComp {
@@ -305,4 +305,3 @@ class MyService {
305305
this.greeting = 'hello';
306306
}
307307
}
308-

0 commit comments

Comments
 (0)