【问题标题】:Angular Drop Down Not Showing Elements角度下拉不显示元素
【发布时间】:2018-02-17 03:28:12
【问题描述】:

在我的 html 组件中,我有以下内容:

        <select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
          <option selected="" value=""></option>
          <option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
            {{ powerPlantType }}
          </option>
        </select>

从下面的屏幕截图可以看出,它显示良好:

如何在页面加载时添加一条显示“--Select Type--”文本的消息?

编辑:根据下面帖子的建议,我仍然无法让它工作:所以当页面加载时,下拉菜单仍然是空的,没有预期的默认测试“--Select Type--”

但是在选择下拉列表时似乎出现了测试!

我宁愿在页面加载时也这样:

【问题讨论】:

    标签: angular angular2-template dropdown


    【解决方案1】:

    将您的 html 更改为以下内容:

    <select class="hideLabel form-control" [(ngModel)]="model.powerPlantType" name="powerPlantType" (change)="selectName();">
        <option selected="" value="">--Select Type--</option>
        <option [ngValue]="powerPlantType" *ngFor="let powerPlantType of powerPlantTypes">
            {{ powerPlantType }}
        </option>
    </select>
    

    【讨论】:

    • 它有点工作,但我希望这个文本--选择类型--在页面加载时出现。看我编辑的帖子!我添加了 2 个屏幕截图来解释我在尝试您的建议时遇到的问题!
    • 我看不到已编辑的帖子,您是否添加了另一个屏幕截图?
    • 对不起!现在就来看看吧!
    • 你有什么想法吗?
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 2020-09-12
    • 2022-06-27
    • 1970-01-01
    相关资源
    最近更新 更多