【问题标题】:I'am unable to populate the saved percent value in angular material mat select我无法在角材料垫选择中填充保存的百分比值
【发布时间】:2020-02-03 07:10:33
【问题描述】:

我在 mat-option 中使用 mat-form-field 列出 1-100 个数字。保存后下拉菜单中没有显示保存的值。**

<mat-form-field class="full-wid" appearance="outline">
                  <mat-label>Percentage 1 (%)</mat-label>
                  <mat-select matTooltip="Please percentage" class="numbers" [required]="percentTorF"
                    (selectionChange)="selected2()" [formControl]="salaryform.controls['Percentage1']"
                    [(ngModel)]="percentValue1">
                    <mat-option *ngFor="let n1 of numbers1" [value]="n1">{{ n1 }}</mat-option>
                  </mat-select>
                  <mat-error *ngIf="salaryform.controls['Percentage1'].hasError('required')">
                    Percentage is required</mat-error>
</mat-form-field>

**

【问题讨论】:

  • {{percentValue1 | json }} 的结果是什么?加上显示numbers1数组的样本数据
  • 如果你可以为它创建一个stackblitz会更好。
  • 公众号1 = []; for (让 i = 1; i
  • 您在使用表单吗?反应性?
  • 是的,使用反应形式。

标签: angular typescript angular-material


【解决方案1】:

在填写表单值之前使用toString()将百分比整数值转换为字符串。

【讨论】:

  • 你能告诉我必须在哪里转换百分比整数值吗?
  • 当您获取详细信息以填写表单时:
  • Edit(data){this.Form = this.fb.group({ percentage:Data.percentage.toString()})} 类似的东西
  • 如果你使用formgroup,你可以直接只使用formControlName而不是formControlngModel组合使用。此外,请确保您获取的值在 numbers1 数组中可用。
  • public numbers1 = Array(100).fill().map((e,i)=&gt;i+1)代替public numbers1 = []; for (let i = 1; i &lt;= 99; i++) { this.numbers1.push(i); }
猜你喜欢
  • 2019-03-11
  • 2021-02-17
  • 1970-01-01
  • 2018-04-30
  • 1970-01-01
  • 2020-07-05
  • 2018-06-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多