Znowman Znowman - 1 month ago 16
JSON Question

Angularjs syntax error

Trying to output data from an API:

{{forecast.list.rain.3h}}


Gives an error:
Syntax Error: Token '.3' is an unexpected token at column 19 of the expression [forecast.list.rain.3h] starting at [.3h].
saying that .3 is the error, integers not allowed in {{....}}?
This seems problematic when the data is stored like this:

rain:Object
3h:0.005

Answer

Well you can't reference this property with dot-notation since a valid identifier may not start with a number. Use {{forecast.list.rain['3h']}} instead.

Comments