简体   繁体   English

破折号案例(Kebab案例)数据绑定在角度2

[英]Dash case (Kebab case) data binding in angular 2

In Angular 2, I call a web service and it respond data properly, 在Angular 2中,我调用了Web服务,它可以正确响应数据,

but when I'm going to bind that data, It's not binding for Kebab case property( company-name ). 但是,当我要绑定该数据时,它并不与Kebab案例属性( company-name )绑定。

<div *ngFor="let company of companyDetailsList">
     {{company.company-name}}
</div>

but it's bind perfect for 但是它非常适合

<div *ngFor="let company of companyDetailsList">
     {{company.address}}
</div>

In JavaScript dashes are not allowed in variable names. 在JavaScript中,变量名称中不允许使用破折号。 The interpreter will think this is a subtraction. 口译员会认为这是一个减法。

You can however access the property like this: 但是,您可以这样访问属性:

<div *ngFor="let company of companyDetailsList">
     {{company["company-name"]}}
</div>

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

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