如何在angular中获取component.ts中的数据属性值2

How to get data attribute value in component.ts in angular 2

我正在尝试在 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的值?

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

bedRoom.getAttribute('data-price');