Angular multi select dropdown

ArunM

I would like to design a multi select drop down functionality in angular using bootstrap 4. Following is the image below.

enter image description here

Following is my implementation as of now.

             <div class="form-group">
                      <label>Employee privilege</label>
                      <select id="employeePrivelege" data-style="btn-default" 
                      class="selectpicker form-control" 
                      formControlName="employeePriveleges"
                      multiple data-max-options="2">      
                        <option selected>Mustard</option>
                        <option selected>Barbecue</option>
                          </select>
                    </div> 

I have 2 problems

  1. An element is not selected if I add the selected attribute on option

I know this is happening because of the fact that I do not use jQuery and I do not want to add JQuery as this is not recommended in Angular.

Questions I have is

  1. What is the simplest option of implementing a multiple dropdown UI component in Angular with or without bootstrap 4
ChrisS1918

I tried your code but the selected attribute works fine for me.

I created a snippet at w3schools that shows that it works: link to snippet

It looks like it's not selected because the selected options are greyed out because the control is inactive. If you add another option however that is not selected, you can see the difference. I created another snippet here.

My simplified code looks like that:

<select name="Sauces" multiple>
  <option value="Mustard">Mustard</option>
  <option selected value="Barbecue">Barbecue</option>
  <option value="Ketchup">Ketchup</option>
  <option selected value="Mayonaise">Mayonaise</option>
</select>

Also I found an Angular component which works great:

https://www.npmjs.com/package/ng-multiselect-dropdown

I created a stackblitz demonstrating the component with your data here

I hope this helps you further.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Angular Material multi Select

分類Dev

multi select checkable dropdown check boxes in alert dailog in android

分類Dev

Angular - Mark option in select dropdown as selected by default

分類Dev

Angular State Dropdown Bound to Country Select

分類Dev

How to use a select option dropdown in an Angular Directive?

分類Dev

Angular material multi select get selected value on hide

分類Dev

Angular Bootsrap Multi Select Add Remove Componenet Model

分類Dev

Select dropdown color changing

分類Dev

Angular 6 cannot automatically select/bind dropdown list value from supplied object

分類Dev

Multi select in tableView javafx

分類Dev

Jquery Select Multi divs

分類Dev

How to convert a select dropdown into an ul dropdown?

分類Dev

Blazor onchange event with select dropdown

分類Dev

Converting a select form to a dropdown buttons

分類Dev

Django - dropdown form with multiple select

分類Dev

Disabling option in a select dropdown with jQuery

分類Dev

select randomly from dropdown list?

分類Dev

select randomly from dropdown list?

分類Dev

Adding images to Vue Select dropdown?

分類Dev

select elements in dropdown marked as a list

分類Dev

Customize select2 multi select

分類Dev

Slick Grid Multi select issue

分類Dev

Angular Material Multi Selectは、非表示時に選択された値を取得します

分類Dev

angular2-dropdown not updating

分類Dev

angular bootstrap dropdown in a table cell

分類Dev

Vaadin DropDown/Select/Spinner best practice?

分類Dev

Selenium Select - Selecting dropdown option by part of the text

分類Dev

Dependent Dropdown Contents with jquery-select2

分類Dev

Rails select_tag / dropdown with enums

Related 関連記事

ホットタグ

アーカイブ