简体   繁体   中英

Angular - How can I put icons in the html select option

I have a component that shows a list of accounts. I would like to show not only the account number but also the currency with an icon or image of country flag.

This is my component:

<select name="drpAccounts" class="form-control"[(ngModel)]="accountSelected" (change)="handleChangedDrpAccount($event)">
    <option *ngFor="let account of accounts" [ngValue]="account">
        {{ account.formattedNumber }}
    </option>
</select>

I found many projects of libraries on github but I want something simple. Thanks in advance.

EDIT:

After some proofs with this code

<select name="drpAccounts" class="form-control" [(ngModel)]="accountSelected" (change)="handleChangedDrpAccount($event)">
    <option style="background-image:url(assets/img/country-flag.png);" *ngFor="let account of accounts" [ngValue]="account">
        {{ account.formattedNumber }}
    </option>
</select>

I realized that it works when I put the style in the select tag

<select style="background-image:url(assets/img/country-flag.png);" ... >

and that it's I don't want

在此处输入图片说明

This has nothing to do with angular oder typescript. It's a html/css related topic. Maybe this helps:

How to add a images in select list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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