Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion modules/angular2/src/core/compiler/directive_metadata_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ export class DirectiveMetadataReader {

componentDirectivesMetadata(annotation:Component):List<Type> {
var template = annotation.template;
return isPresent(template) && isPresent(template.directives) ? template.directives : [];
var result:List<Type> = ListWrapper.create();
if (isPresent(template) && isPresent(template.directives)) {
this._buildList(result, template.directives);
}
return result;
}

_buildList(out:List<Type>, tree:List<any>) {
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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]);
});
});
});
}
3 changes: 1 addition & 2 deletions modules/angular2/test/core/compiler/integration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class PushBasedComp {

@Component({
template: new TemplateConfig({
directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp]
directives: [MyDir, [[ChildComp], SomeTemplate, PushBasedComp]]
})
})
class MyComp {
Expand Down Expand Up @@ -305,4 +305,3 @@ class MyService {
this.greeting = 'hello';
}
}