简体   繁体   中英

Get selected values from multiple select in Angular 7

I have the following select control which is populated with country names:

<select class="form-control m-select2" id="countries-select" multiple="multiple" formControlName="country">
    <option *ngFor="let country of countries" [value]="country.code">{{ country.name }}</option>
</select>

When I try to get the selected values, I'm getting them in this form:

"index: 'value'"

For example:

4: 'US'

How do I get 'US' only without that index value?

Thanks.

If you don't find another solution you can always parse the string to extract the value you want:

selectedValue.split("'")[1]

This should probably be your last resort, though.

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