Hello,
Using Angular, I’m trying to do a tree view listing something like a classified listing and I’m not sure how to go about displaying the sub category.
its easy displaying the parent category using the *ngfor directives but stuck as to how to display child category in Angular.
Looking for examples and ideas…the code i have is to display parent category and the code to display sub category is externally broken. With Angular I’m somewhat stuck as to how to loop inside a loop to display the information.
sample array:
categoryArray =
[{ “categoryId”: 1, “categoryName”: “Ford”, “subCategoryName”: “Mustang”, “year”: 1996 },
{ “categoryId”: 2, “categoryName”: “Honda”, “subCategoryName”: “Element”, “year”: 1997 },
{ “categoryId”: 3, “categoryName”: “GMC”, “subCategoryName”: “Suburban 2500”, “year”: 1994 },
{ “categoryId”: 4, “categoryName”: “Subaru”, “subCategoryName”: “Legacy”, “year”: 1992 },
{ “categoryId”: 6, “categoryName”: “Mercedes-Benz”, “subCategoryName”: “GLK-Class”, “year”: 2012 },
{ “categoryId”: 7, “categoryName”: “Honda”, “subCategoryName”: “Accord”, “year”: 1998 }]
the output should look like this:
example out put:
Honda Ford
- Element - Car 1
- Accord - Car 2
- etc - etc