-1

I am not able to display the array of elements values in html page.

I have selected values of json array of object, from this result I removed the duplicate category values, and that values convered to array of string. and I listed that array of element. But I don't know to display the forEach element in a ngFor loop in angular.

export class PreviewComponent implements OnInit {
public menus : any = [];
newuniq: any[][];

ngOnInit() {
 this.newmenuService.getProducts()
    .subscribe(resp=>{
      this.menus = resp;
    console.log("cart",this.menus)
    })
 const newuniq = [...new Set(this.menus.map(item => item.category
      ))];

 newuniq.forEach(function(element) {
      console.log("element",element);
      
    });

}

component.html {{newuniq}}

  • Does this answer your question? [Angular - How to display data from an array of an array?](https://stackoverflow.com/questions/52063766/angular-how-to-display-data-from-an-array-of-an-array) – Code Spirit Mar 24 '22 at 13:19
  • I don't understand, you did the most difficult part. Did you try something like `
    {{menu.category}}
    ` Can you be more specific about where you are stuck ?
    – Arnaud Denoyelle Mar 24 '22 at 13:20
  • Normally, you should be able to display an array like this `
    {{n}}
    ` (but you also have to set this.newuniq = newuniq; in your .ts file)
    – angularQuestions Mar 24 '22 at 13:24
  • @CodeSpirit yes, that is my question – user18513197 Mar 24 '22 at 13:27

1 Answers1

0

<div *ngFor="let item of newuniq">
{{item.category}}
</div>
vahid mehrjooei
  • 69
  • 1
  • 2
  • 9