0

HTML -

<mat-cell fxFlex="15%" *matCellDef="let element"> {{ element?.appointment }} {{ element?.appointment }} </mat-cell>
    <mat-cell fxFlex="15%" *matCellDef="let element"> {{ element?.gardener.first_name }} {{ element?.gardener.last_name }} </mat-cell>

Data from backend -

0: {
appointment: 100
gardener.first_name: "dfr"
gardener.last_name: "cvg"
}

Here I am having issue with first_name and last_name. Appointment is coming on my html part fine. But for first_name and last_name I do not have any clue why this is happening but no data is shown even if I console the values. Can someone please help?

  • @HereticMonkey It is showing error. "Cannot read property 'first_name' of undefined". {{ element?.gardener['first_name']}} – Umang Mehra Nov 04 '20 at 14:29
  • As it says in the answers, you need to put brackets and quotes around the entire key with the special characters, so `element?.['gardener.first_name']` – Heretic Monkey Nov 04 '20 at 14:34
  • @HereticMonkey For this it is showing this error - Parser Error: Unexpected token [, expected identifier or keyword – – Umang Mehra Nov 04 '20 at 14:36
  • Then you are using an outdated version of Angular or TypeScript or browser. That is the appropriate syntax for [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#Optional_chaining_with_expressions) See also [Using optional chaining operator for object property access](https://stackoverflow.com/q/58780817/215552) – Heretic Monkey Nov 04 '20 at 14:39

1 Answers1

1

Try

{{ element['gardener.first_name'] }}
JerryLee
  • 153
  • 1
  • 11
  • For this it is showing this error - Parser Error: Unexpected token [, expected identifier or keyword – Umang Mehra Nov 04 '20 at 14:35
  • 1
    If you see a comment starting with "Does this answer your question?" followed by a link, please follow the link and decide if its answers answer the current question. If so, please do not answer the question. – Heretic Monkey Nov 04 '20 at 14:36
  • Sorry, remove dot before `[` – JerryLee Nov 04 '20 at 14:36