Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用角度2+;将单击的数据表行的值写入子组件html;_Angular - Fatal编程技术网

Angular 使用角度2+;将单击的数据表行的值写入子组件html;

Angular 使用角度2+;将单击的数据表行的值写入子组件html;,angular,Angular,我已经创建了一个数据表,如果单击一行,我需要子组件中的数据 在控制台日志中,我获取了行数据,但无法在子组件中读取它。 我对Angular非常陌生,我知道如何给child编写一些简单的字符串,但不是数组或对象 我为我的问题创建了一个stackblitz,如果你打开控制台并点击一行你就得到了对象,如何在子组件的html中写入对象数据 您需要将其作为输入传递给子组件: ts 。。。 } html 像这样尝试: app.component.html <app-child-component [r

我已经创建了一个数据表,如果单击一行,我需要子组件中的数据

在控制台日志中,我获取了行数据,但无法在子组件中读取它。 我对Angular非常陌生,我知道如何给child编写一些简单的字符串,但不是数组或对象

我为我的问题创建了一个stackblitz,如果你打开控制台并点击一行你就得到了对象,如何在子组件的html中写入对象数据


您需要将其作为输入传递给子组件:

ts

。。。 }

html

像这样尝试:

app.component.html

<app-child-component [rowData]="rowData"></app-child-component>
<p *ngFor="let item of rowData | keyvalue">{{item.key | titlecase }}: {{item.value}}</p>
child.component.ts

rowData = {};


toggleDetails(row) {    
  this.rowData = row;
}
@Input() rowData: any;
child.component.html

<app-child-component [rowData]="rowData"></app-child-component>
<p *ngFor="let item of rowData | keyvalue">{{item.key | titlecase }}: {{item.value}}</p>
{{{item.key | titlecase}}:{{{item.value}