0
concerts: [
    {
        key: "field_concerts_time",
        lbl: "Date"
    }, {
        key: ["field_concert_fromtime", "field_concert_totime"],
        lbl: "Time",
        concat: "to"
    }, {
        key: "field_concerts_agereq",
        lbl: "Age Requirements"
    }, {
        key: "field_concerts_dresscode",
        lbl: "Dress Code"
    }, {
        key: "field_concerts_prices",
        lbl: "Prices"
    }

]

 descriptions: {

 "field_concerts_time": [

  {
  "value": "2019-09-16T00:00:00",
  }
  ],

"field_concert_totime": [

  {
  "value": "1:00AM"
  }

  ],

 "field_concert_fromtime": [

  {
  "value": "7:30PM"
  }

  ]
  }

I have concerts array and descriptions object i want to take the "key" from the concerts and take value for that field

    <p *ngFor="let otherdetail of otherdetailsarray">
    <span *ngIf="descriptions[otherdetail.key][0].value !== null"> 
      {{otherdetail.lbl}} :</span>
    <span *ngIf="descriptions[otherdetail.key][0].value !== null && 
      descriptions[otherdetail.key][0].value !== undefined"> 
      {{descriptions[otherdetail.key][0].value }}</span>
  </p>

I got the value for the 1'st index's key "field_concerts_time" and took value from description using above tags. I want this code to support "key: ["field_concert_fromtime", "field_concert_totime"]"

1 Answer 1

1

Here you go. Check whether you've reached the concert's Time-object. If so, handle the key as an array by indexing fields 0 and 1 additionally.

<p *ngFor="let otherdetail of otherdetailsarray">
<span *ngIf="descriptions[otherdetail.key][0].value !== null"> 
  {{otherdetail.lbl}} :</span>

<span *ngIf="otherdetail.lbl !== 'Time' &&
  descriptions[otherdetail.key][0].value !== null && 
  descriptions[otherdetail.key][0].value !== undefined">
  {{descriptions[otherdetail.key][0].value }} 
</span>

<span *ngIf="otherdetail.lbl == 'Time' &&
  descriptions[otherdetail.key[0]][0].value && 
  descriptions[otherdetail.key[1]][0].value"> 
   {{descriptions[otherdetail.key[0]][0].value }} {{otherdetail.concat}}
  {{descriptions[otherdetail.key[1]][0].value }}
  </span>

</p>

This should do the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I had to correct my code once again as there was a typo. Should work now.

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.