我的默认选项未显示在我的选择中

时间:2018-10-23 12:03:30

标签: html angular

我有一个选择,但是默认选项“ Primeiro filtro”没有显示:

enter image description here

我的模板:

<div class="select">

  <select [(ngModel)]="controlaRadios" name="tipoDoProdutoName" class="select-text">
    <option class="dropdown-item" disabled selected value>Primeiro filtro</option>
    <option value="1" class="dropdown-item">Todos</option>
    <option value="2" class="dropdown-item">Tipo de anúncio</option>
  </select>

  <span class="select-highlight"></span>
  <span class="select-bar"></span>

</div>

TS:

controlaRadios: any = "Primeiro filtro"

2 个答案:

答案 0 :(得分:2)

在这里看看并尝试适应。希望这会有所帮助。

.html

<select class="form-control" type="text" [(ngModel)]="selectedType">
        <option *ngFor="let type of types" [ngValue]="type">{{type}}</option>
</select>

.ts

types: Array<Object> = ['Default option', 'First option', 'Second option']
selectedType = this.types[0];

答案 1 :(得分:0)

尝试一下。希望它对你有用:)      

  <select [(ngModel)]="controlaRadios" name="tipoDoProdutoName" class="select-text">
    <option value="Primeiro filtro" class="dropdown-item">Primeiro filtro</option>
    <option value="1" class="dropdown-item">Todos</option>
    <option value="2" class="dropdown-item">Tipo de anúncio</option>
  </select>

  <span class="select-highlight"></span>
  <span class="select-bar"></span>

</div>