1

I am trying to access a JSON key value( with space) inside a HTML attribute. My page is on Angular 10 version and I am binding src attribute to a key in JSON.

<td mat-cell *matCellDef="let element">    
  <img [src]="element.Player Name"/>   
</td>

JSON

{
"Name": "Richard",
"Player Name": "https://sampleURl/example.jpg"
}

Here 'Player Name' is the key with space. I tried:

<td mat-cell *matCellDef="let element">    
  <img [src]="element[Player Name]"/>   
</td>

This works for normal binding but not here. Thanks for any help

1
  • I believe element['Player Name'] works. element.Player_Name may also be worth a try. Commented Jan 15, 2021 at 15:30

1 Answer 1

1

In order to bind using an actual string (and not something for angular to translate), use 'actual string', in your case:

<td mat-cell *matCellDef="let element">    
  <img [src]="element['Player Name']"/>   
</td>
Sign up to request clarification or add additional context in comments.

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.