我的问题很简单,我有一个 JSON Typescript 对象,我喜欢迭代 trought JSON 属性
{"work_type":"Fabricación","work_type_resp":"Mesa","looking_for":"Relación Calidad/Precio","image":"https://s3-sa-east-1 .amazonaws.com/online-quotation-images/153366018967.png","width":"22","high":"34","depth":"","modifications":"mod"}
使用的代码是以下 Angular TypeScript 组件:
export class DetailsOnlineQuoteModalComponent implements OnInit {
@Input() title;
@Input() values:string;
properties:JSON;
constructor(public activeModal: NgbActiveModal) { }
ngOnInit() {
this.properties=JSON.parse(this.values);
console.log(this.properties);
}
}
我真正需要的是遍历 JSON 的键值属性并将它们显示在我的 HTML 中。
非常感谢!
最佳答案
如果您使用的是 angular 6.1,请使用键值管道
<div *ngFor="let title of data | keyvalue">
{{title.key}}
</div>
对于 Angular 5
<div *ngFor="let key of dataKeys">
{{key}} ------------- {{data[key]}}
</div>
get dataKeys() { return Object.keys(this.data); }
关于json - 如何在 TypeScript 中迭代 JSON 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51732524/