Custom dropdown in angular

Viewed 232

How to create a custom dropdown in angular and load data

<select dropdown name="mydropDown" class="form-control dropdown-toggle">
    <option *ngFor="let item of testList" [value]="item.value">
          {{item.name}} 
    </option>
</select>
1 Answers

Try this!

In component ts

export class TestComponent implements OnInit {
  testList = [{ value: '1', name: 'A' }, { value: '2', name: 'Test B' }];

  constructor() { }

  ngOnInit(): void {
  }
}

In component html

<select dropdown name="mydropDown" class="form-control dropdown-toggle">
    <option *ngFor="let item of testList" [value]="item.value">
          {{item.name}} 
    </option>
</select>
Related