【发布时间】:2021-12-02 10:43:08
【问题描述】:
在我的应用程序中,我有 json 数组,我可以显示这些数据。所有数据都有单选按钮。我想要的是当我单击单选按钮时,该 json 数组项的数据将以 html 格式打印在另一个组件中。像下面的东西。 This is how it is showing
下面有我的 product.component.ts。
ngOnInit() {
this.wordpressService.apiCall().subscribe((data)=>{
console.warn("get api data ",data);
this.title=data;
})
}
radioHandle(event : any){
this.post=event.target.value;
}
然后在我的 product.component.html 中显示一些 json 数据,如下所示。
<div class='container'>
<div id="leftDiv">
<div *ngFor="let data of title">
<p>
<input type="radio"
name="posts"
value="{{data | json}}"
(change)="radioHandle($event)">
{{data.id}}
</p>
</div>
</div>
<div id="rightDiv">
<app-productDisplay [parentData]=post></app-productDisplay>
</div>
</div>
现在我想将选定的数据传递给另一个名为 productDisplay.component.ts 的组件
@Input() public parentData: any;
并在productDisplay.component.html中显示数据
{{parentData}}
它有效。但问题是它是显示 json 对象。但我想打印 json 对象的一些属性而不是整个 json
【问题讨论】:
-
也许
{{parentData | json}}会有所帮助 -
@EMilen 它显示 json 数据。我想单独打印属性。类似于 parentData.Id 的东西。但它不起作用