[英]How do I input data attribute values with multiple classes to a div after button click?
[英]How do I add multiple values to a single data attribute in angular?
我正在尝试使用angular将多个值添加到data-content
属性。 为了使我能够定位数据内容属性,我使用[attr.data-content]
角度代码使其有效。
我有一个我要遍历的地址列表,我正在尝试向数据内容属性添加多个值,例如address.FriendlyName和address.Description。 当我添加多个属性时,它将不起作用。 有谁知道如何使它工作?
请参见下面的代码:
<select class="selectpicker form-control m-input">
<option *ngFor="let address of dummyAddresses" [attr.data-content]="address.FriendlyName address.Description">This is a test</option>
<option data-content="Add …">Add new address</option>
</select>
您可以在属性绑定内进行字符串连接:
<select class="selectpicker form-control m-input">
<option *ngFor="let address of dummyAddresses" [attr.data-content]="address.FriendlyName + ' ' + address.Description">This is a test</option>
<option data-content="Add …">Add new address</option>
</select>
您应该确保您的选项不包含空格,以避免产生工件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.