3

How to create a typescript component for simple html dropdown?

    <div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    Dropdown
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li><a href="#">Action</a></li>
    <li><a href="#">Another action</a></li>
    <li><a href="#">Something else here</a></li>
    <li role="separator" class="divider"></li>
    <li><a href="#">Separated link</a></li>
  </ul>
</div>

How to implement of this?

1 Answer 1

1
<select [(ngModel)]="whereWeStoreTheValue">
  <ng-container *ngFor="let option of options">
    <option *ngIf="!option.isDivider" [ngValue]="option">{{option.name}}</option>
    <option *ngIf="option.isDivider" disabled>{{option.name}}</option>

  </ng-container>
</select>
class MyComponent {
  options = [
   {name: 'Action'}, 
   {name: 'Another action'},
   {name: 'Something else here'},
   {isDivider: true},
   {name: 'Separated link}
  ];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works, and how implement like dropdown button?
Sorry, don't know what "like dropdown button" means. You can have a look at the components provided by github.com/ng-bootstrap/ng-bootstrap or github.com/angular/material2/blob/master/src/lib/menu/README.md

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.