2
votes

I recently started using ViewChildren and ContentChildren in Angular 2, but had now been wondering if these could be used in ES6 without TypeScript annotations as well.

The TypeScript syntax, as per the docs, is as follows:

@ViewChild(ItemDirective) viewChild: ItemDirective;

Alternatively, as per here:

// myVideo == #my-video
@ViewChild('myVideo') myVideo: any;

Now, the corresponding source has Metadata classes for ViewChild and co., which I recall could be used to add some of the other annotations in plain JS. So I'm thinking it should be doable, but I'm not really sure how in this case. Would anyone be able to shed some light on this?

1

1 Answers

2
votes

I think that such decorators should work with ES6 / ES7 (you need to include ES7 decorators in addition to ES6 itself). The latter does have are class and property decorators so you should be able to transpile the ViewChild decorator.

It's not the same for parameter decorators that aren't supported...

See this answer and its comments:

This link could be also useful: