输入中的默认值选择Angular

时间:2017-08-27 17:50:04

标签: html angular

libros.component.ts

export class LibrosComponent implements OnInit {
          public order;
          ...

libros.component.html

<div class="form-group">
          <label for="selectOrden">Ordenar</label>
          <select class="form-control input-sm" #ordenar="ngModel" [(ngModel)]="order" name="ordenar" id="selectOrden" (change)="findOrder()">
              <option>Alfabético</option>
              <option>Fecha</option>
              <option>Valoración</option>
          </select>
 </div>

加载页面时,此选择如下:

enter image description here 但我想要一个默认值,如下所示:

img01 我也尝试使用selected =“selected”,但它在这里不起作用。

由于

1 个答案:

答案 0 :(得分:1)

只需使用您要在orderconstructor方法中显示的值初始化字段ngOnInit()