Alex
Alex

Reputation: 177

Interate objectKeys *ngFor

I have a object like this

"Stage" : { // -> vaga.stage
"ID01" : { // -> stage.code
  "abeb5220-2003-4b8b-a6d5-853a40ca7d60" : { //candidate
    "email" : "[email protected]",
    "name" : "Full name"
  }
}

}

hasProperty method

     hasProperty(obj, property) {
    // debugger;
    return typeof obj == "object" && obj.hasOwnProperty(property);
  }

My Html file

<ng-container *ngIf="hasProperty(vaga.stage, stage.code)">
                  <div
                    ngxDraggable
                    (drag)="dragCandidate($event)"
                    class="candidate ngx-dnd-item"
                    [model]="{
                      codCandidate: candidate,
                      nameCandidate: vaga.stage[stage.code][candidate],
                      codeLastStage: stage.code,
                    }"
                    *ngFor="let candidate of objectKeys(vaga.stage[stage.code]); let i = index"
                  >
                    {{ vaga.stage[stage.code][candidate] }}
                  </div>

In html, how i fetch the name value of object?

Upvotes: 0

Views: 67

Answers (1)

Sook Yan
Sook Yan

Reputation: 128

Let assume the word "objectKeys" is representing your object in your window typescript.

*ngFor = "let data of objectKeys">
    {{ data.Stage.ID01.abeb5220-2003-4b8b-a6d5-853a40ca7d60.name }}

Please let me know if this is working? I am still learning. Thank you.

Upvotes: 2

Related Questions