0

The Employee object in my Angular app contains an array of Skill objects, like below:

export interface IEmployee {
    id: number;
    fullName: string;
    skills: ISkill[];
}

Here is my Skill interface:

export interface ISkill {
    skillName: string;
    experienceInYears: number;
    proficiency: string;
}

I am able to use interpolation to display employee details like so:

{{employee.fullName}}

Now, I am trying to display the employee's skill.

Below, I am able to display the first skill:

{{employee.skills[0]?.skillName}}

But I want to display all of the skills associated with that employee, not just the first one.

I think the solution might have something to do with ngFor, but not sure exactly how to implement it.

Can someone please tell me how I can loop through the skills array to display all skillName's in the above code?

4 Answers 4

1

You can simply use ngFor for the skills of the particular employee.

Something like this should do the trick.

<div *ngFor="let skill of employee.skills">
  {{skill.skillName}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

You can loop over your skills array like this:

<div *ngFor="let skill of employee.skills" >
   <span>{{skill.skillName}}</span>
   <span>{{skill.experienceInYears}}</span>
   <span>{{skill.proficiency}}</span>

</div>

You can find more info here

Comments

1
<div *ngFor="let skill of employee.skills">
    <div>{{ skill.skillName }}</div>
    <div>{{ skill.proficiency }}</div>
    <div>{{ skill.experienceInYears }}</div>
</div>

Comments

1

Read the docu for more informations: https://angular.io/guide/displaying-data

<div *ngFor="let skill of employee.skills">
      {{ skill.name }}
    </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.