-1

I have an object defined as:

{ "IP-Address":"1.1.1.1", "name":"User1" }

in HTML

{{data.IP-Address}}

It shows an error The righthand side of arithmetic operator must be type 'any'. Because of Hyphen(-). How can I resolve that?

Edric
  • 24,639
  • 13
  • 81
  • 91
Navin M
  • 1
  • 5
  • its interpreting it as (data.IP) minus (Address). You can use a array style notation like ```data["IP-Address"]``` – Akin Okegbile Jul 16 '20 at 15:15
  • Does this answer your question? [How do I reference a javascript object property with a hyphen in it?](https://stackoverflow.com/questions/7122609/how-do-i-reference-a-javascript-object-property-with-a-hyphen-in-it) – Akin Okegbile Jul 16 '20 at 15:17

2 Answers2

2

Try with

{{data['IP-Address']}}

But I'd also suggest to manage more simple property names so you may use the safe navigation operator in case it could be useful on your app.

So you could do this

{{data?.ipAddress}}

and prevent possible error

TypeError: Cannot read property 'name' of null.

in case you're rendering when your object is still null or undefined.

Daniel Guzman
  • 588
  • 2
  • 8
0

Change your html code to {{data['IP-Address']}}

ViqMontana
  • 5,090
  • 3
  • 19
  • 54