• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

373
Views
Using Typescript Variable to create img src

I have an array which contains a list of categories, below is an example of one category: description: "test"

[0]
    icon: "assets/images/test1"
    name: "test"
[1]
    icon: "assets/images/test2.png"
    name: "test 2"

I am trying to loop through this array and display both the category name and the icon, however, displaying the icon isn't working.

<ng-container *ngFor="let category of this.categories>
   {{category.name}}  
   <img src={{category.icon}}/>               
</ng-container>

Does anyone know how to do this? Thanks

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

I'm not an angular expert, but shouldn't you use the [] syntax for property binding?

E.g.:

<ng-container *ngFor="let category of this.categories">
   {{category.name}}  
   <img [src]="category.icon"/>               
</ng-container>

Also, you're missing a " at the end of categories.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error