【问题标题】:Dynamically adding the input fields [closed]动态添加输入字段[关闭]
【发布时间】:2019-05-21 14:05:07
【问题描述】:

我有一个名为 home 的组件,它有 3 个输入字段(国家、城市、州),如下图所示:

我正在动态添加输入字段,它工作正常,如下图所示:

但我的要求是:在Country 字段而不是input field,我想要dropdown(选择组件)。但我无法做到。 Stackblitz DEMO

【问题讨论】:

标签: angular typescript angular-material angular6


【解决方案1】:

您的代码中包含所有这些优点,您只需将输入更改为matSelect。

<mat-select placeholder="Country" [(ngModel)]="newAttribute.country" name="food">
  <mat-option *ngFor="let country of countries" [value]="country.value">
    {{country.viewValue}}
  </mat-option>
</mat-select>

Demo

【讨论】:

  • 添加假设我想改变国家,我需要 dropdwon。
  • @Empty_Soul 你的意思是?我不明白
  • 如果我想在添加后更改国家名称。我想回到第一组input input fields,我有dropdown(country) 和2 个input fields(city, state),带有add 按钮。
  • 我需要那个下拉列表(国家),即使在添加之后。
  • @Empty_Soul 我更新了演示链接,请看一下
猜你喜欢
  • 1970-01-01
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多