【问题标题】:How to get data attribute value in component.ts in angular 2如何在角度2中获取component.ts中的数据属性值
【发布时间】:2017-06-17 00:52:40
【问题描述】:

我正在尝试获取 angular2 中 component.ts 中数据属性的值。

1) form2.component.html

<md-select  placeholder = "BedRooms" [formControl]="userForm.controls['bedRooms']" >
    <md-option #bedRoom  *ngFor="let bedRooms of formSettings?.prices?.pricingParams?.bedRooms" [value] = bedRooms.title [attr.data-price] = bedRooms.price (click)="test(bedRoom)"> {{bedRooms?.title}} </md-option>
</md-select>

如何在测试函数中获取data-price的值?

【问题讨论】:

标签: angular-material2


【解决方案1】:

您可以通过引用bedRoom 访问data-price 的值,如下所示。

bedRoom.getAttribute('data-price');

【讨论】:

    猜你喜欢
    • 2017-11-10
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2022-10-05
    • 2019-08-28
    • 2021-08-23
    相关资源
    最近更新 更多