且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Angular2中的viewContainerRef获取子组件

更新时间:2023-11-22 18:02:16

ViewContainerRef类具有用于访问子级的length和get(index)属性.在此处查看API:

The ViewContainerRef class has length and get(index) properties for accessing children. See the API here:

https://angular.io/docs/ts/latest/api/core/index/ViewContainerRef-class.html

因此,要引用特定的子代,请使用viewContainerRef.get(childOfInterestIndex),并使用诸如for(var index = 0; index < viewContenrRef.length; index++)

So to reference a specific child, you use viewContainerRef.get(childOfInterestIndex), and to work on all children you use a for loop, using something like for(var index = 0; index < viewContenrRef.length; index++)