Javascript 从Angular 2中的父组件访问子组件值的简单方法
假设我的结构如下所示:Javascript 从Angular 2中的父组件访问子组件值的简单方法,javascript,angular,typescript,Javascript,Angular,Typescript,假设我的结构如下所示: <my-table> <my-row> <my-col>Value 1</my-col> <my-col>Value 2</my-col> </my-row> <my-row> <my-col>Value 3</my-col> <my-col>Value
<my-table>
<my-row>
<my-col>Value 1</my-col>
<my-col>Value 2</my-col>
</my-row>
<my-row>
<my-col>Value 3</my-col>
<my-col>Value 4</my-col>
</my-row>
</my-table>
我对这个变量所做的任何更改(排序、过滤等)都必须动态呈现
如何做到这一点
//编辑
我无法使用nested*ngFor执行此操作,因为我希望在我的列中包含其他组件,例如引导进度条等。
关于简单的解决方案是将
列的数组传递给每个行,即。
我的表格
组件模板将是
<my-row ng-repeat="row in rows" cols="row" />
而cols:'='
是从my table
到my row
的双向绑定,您必须使用嵌套的*ngFor,第一个用于获取每行,第二个用于获取每行中的列:
<my-table>
<my-row *ngFor="let row of arr">
<my-col *ngFor="let column of row">{{ column }}</my-col>
</my-row>
</my-table>
{{column}}
请参阅,也许此解决方案不适合我,因为我可能希望使用其他组件(进度条等)作为解决方案value@MichalBialek我认为您现在想要的东西可以通过属性指令来实现,其中上面代码中的my col
可以是div
,并带有组件的属性(例如,数组中对象的字段)正如我所说,我不能这样做,因为我想在其中包含其他组件
<my-col ng-repeat="col in cols" />
<my-table>
<my-row *ngFor="let row of arr">
<my-col *ngFor="let column of row">{{ column }}</my-col>
</my-row>
</my-table>