It's quite simple, but you need to consider a few points, which I will discuss below, first the code.
, , , @ViewChildren
, , ,
@Component({
selector: 'hello',
template: `<child></child>`,
directives : [Child]
})
export class Parent implements AfterViewInit {
@ViewChildren(Child) children: QueryList<Child>;
afterViewInit() {
for(let child of this.children) {
child.doSomething();
}
}
}
afterViewInit()
, ES6, angular2 Symbol.iterator
. ES5, , typescript (. Plnkr ).
plnkr.
, :)