user9736316
user9736316

Reputation:

How do I add multiple values to a single data attribute in angular?

I'm trying to add multiple values to the data-content attribute using angular. In order for me to target the data-content attribute I'm using the [attr.data-content] angular code for it to work.

I have a list of address I loop through and I'm trying to add multiple values to the data-content attribute e.g. address.FriendlyName and address.Description. When I add more than one property it doesn't work. Does any know how to get it working?

See the code below:

<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 &hellip;">Add new address</option>
</select>

Upvotes: 0

Views: 1056

Answers (1)

Jens Habegger
Jens Habegger

Reputation: 5446

You can do string concatenation inside of attribute bindings:

<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 &hellip;">Add new address</option>
</select>

You should make sure that your options do not include spaces to avoid creating artifacts

Upvotes: 1

Related Questions