Ionic JSON array iteration to view


#1

Hi! I need help to reach the subjectRoles and check if roleName is “SPEAKER” and then display the firstName and lastName

[
  {
    "id": 4,
    "authToken": null,
    "pushToken": null,
    "emailAddress": "bxxxx@yahoo.com",
    "firstName": "Bxx",
    "lastName": "Isxxx",
    "creationDate": 1497545907461,
    "picture": null,
    "subjectRoles": [
      {
        "id": 5,
        "roleName": "AUTHOR"
      }
    ],
    "subjectPermissions": [
      
    ]
  },
  {
    "id": 3,
    "authToken": null,
    "pushToken": null,
    "emailAddress": "asds@xcvx.com",
    "firstName": "Advxcx",
    "lastName": "Adxcvcx ",
    "creationDate": 1497544240146,
    "picture": null,
    "subjectRoles": [
      {
        "id": 4,
        "roleName": "ADMIN"
      }
    ],
    "subjectPermissions": [
      
    ]
  }
]

Here is my current situation.

TS

getSubjects() {
    this.subjectProvider.getSubjects().subscribe(response => {
      console.log(response);
      this.items = response;
      this.items.filter(item => item.subjectRoles[0].roleName === "SPEAKER") //speaker logic
    }
      <ion-item-sliding class="transparent-sliding-item" *ngFor="let item of items">
          <ion-item class="transparent-item">
            <h2 class="speaker-name">{{item.firstName}} &nbsp; {{item.lastName}}</h2>
            <span class="speaker-social-link"><i class="fa fa-linkedin-square speaker-social"></i> &nbsp; {{item.emailAddress}}</span>

          </ion-item>


      </ion-item-sliding>

Kindly help. Thank you!


#2

Sorry, I have resolved.


this.items = response.filter(item => item.subjectRoles[0].roleName === "SPEAKER");