简体   繁体   English

以数字开头的属性名称的角插值

[英]Angular Interpolation of property name starting with digit

I am using the following interpolation in Angular 4: 我在Angular 4中使用以下插值:

{{variable.24h_volume}}

This results in the following error: 这将导致以下错误:

Unexpected token '0.24' at column 5 in [{{variable.24h_volume}}] in ng:///AppModule/Component.html

What is the problem here? 这里有什么问题?

Is it the property name starting with the digit? 是以数字开头的属性名称吗?

Following my comment, I'm putting this as an answer if it can help other people. 根据我的评论,我将其作为可以帮助他人的答案。

To reference a property name starting with a digit or ones the property name is a digit , we can access that property using: 要引用以数字开头或以数字开头的属性名称,我们可以使用以下方法访问该属性:

{{variable['24h_volume']}}

For more on that, please look at similar answers from SO questions like: 有关更多信息,请查看类似SO问题的类似答案:

accessing Object property name as number 访问对象属性名称作为数字

What characters are valid for JavaScript variable names? 哪些字符对JavaScript变量名称有效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM