简体   繁体   English

Angular中启动页面时无法初始显示HTML select选项

[英]Unable to show HTML select option initially when starting the page in Angular

in my ts file I've defined this:在我的 ts 文件中,我定义了这个:

  statuses = [
    { id: 1, name: "Approved" },
    { id: 2, name: "Created" },
    { id: 3, name: "Rejected" },
    { id: 4, name: "Cancelled" },
  ];

in my HTML here is the code在我的 HTML 中,这是代码

<div class="col-1" id="statusFilter">
      <label class="font-weight-bold text-secondary" for="statusFilter">Filter By Status:</label>
      <select
        [(ngModel)]="statusFilter"
        class="form-control"
        (change)="setStatusFilter()">
        <option value="'Choose'" disabled selected><strong> Choose Filter: </strong></option>
        <option *ngFor="let status of statuses" [value]="status.name">
            {{ status.name }}
        </option>
    </select>
</div>

what appears in the Angular App is this empty select, my goal is to make the first tag show its value 'Choose Filter: ' before selecting anything出现在 Angular App 中的是这个空的 select,我的目标是在选择任何内容之前让第一个标签显示其值“选择过滤器:”

here is how it currently appears: enter image description here这是它目前的样子:在此处输入图片描述

and this is what I need it to appear desired result这就是我需要它来显示期望的结果

and for information this is how the select list would appear if I click it, I would be able to see that disabled option inside of it only if clicked but not by default select list clicked有关信息,如果我单击它,这是 select 列表的显示方式,只有在单击时我才能看到其中禁用的选项,但默认情况下不会看到 select 列表已单击

Any idea what i'm doing wrong in here?知道我在这里做错了什么吗?

you should fill statusFilter with "Choose" value in the "ts" file.您应该在“ts”文件中用“选择”值填充statusFilter

statusFilter = 'Choose';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM