【发布时间】:2018-10-05 09:24:58
【问题描述】:
我正在尝试在 Angular 6 中循环使用逗号分隔的字符串。
public getCategory(){
this.Jarwis.getCategorys().subscribe((data: Array<object>) => {
this.categorys = data;
console.log(this.categorys);
});
这是我的函数,它有一个控制台日志
(3) [{…}, {…}, {…}, {…}, {…}, {…}]
0: {id: 4, category_name: "Agriculture", sub_category_names: "Other Agriculture,Vineyards and Wineries,Greenhouses,Tree Farms and Orchards"}
1: {id: 5, category_name: "Automotive and Boat", sub_category_names: "Auto Repair and Service Shops,Car Dealerships,Marine/Boat Service and Dealers,Junk and Salvage Yards"}
2: {id: 13, category_name: "Beauty and Personal care", sub_category_names: "Massage,Tanning Salons,Spas,Hair Salons and Barber Shops"}
我可以在视图页面中显示类别名称
<li *ngFor='let category of categorys'>
<div>{{ category.category_name }}</div>
</li>
但是我怎样才能像这样在不同的 div 中显示 sub_category_names
<div> subcategory_name1 </div>
<div> subcategory_name2 </div>
请帮忙
【问题讨论】:
-
您可能需要将您的
sub_category_names更改为数组
标签: html angular typescript loops twig