对于静态元素,viewchild非常直截了当:
<myChildComponent #childId></myChildComponent>
您可以通过以下方式访问它:
@ViewChild('parent', { read: ViewContainerRef })
我想动态创建元素。
例如,我想创建
<li *ngFor="let user of users">
<myChildComponent #user.name></myChildComponent>
</li>
所以我不知道在高级时我会有多少myCHildCOmponent。这取决于它在ajax调用上返回多少。如何使用viewchild访问组件? THX