Erik Anderson

Erik Anderson

  • 2.1k
  • 4
  • 260

Set a name rather than a number for ID:s returned as strings

Apr 21 2021 1:08 PM
I've a function which returns a list of ID:s as strings. Now it prints out 1,2,3 etc
 
I would like to name each string rather than having it as numbers like:
1 == 'NameOne'
2 == 'NameTwo'
3 == 'NameThree'
 
x.component.ts 
  1. printUser(ids: number[]): string {  
  2.     return ids.sort().join(', ');  
  3. }  
 x.component.html.ts
  1. <div *ngIf="x.users.length > 0"> User:  
  2.     {{ printUser(x.user) }}  
  3. </div>  
 

Answers (1)