【问题标题】:ngIf selected item is a specific value thenng如果所选项目是特定值,则
【发布时间】:2019-08-13 10:02:32
【问题描述】:

我正在尝试使用 Angular 材料在 Angular 中创建一个表单。现在我正在努力解决这个问题。当我在带有标签“type behandeling”的选择选项中选择一个值时,它需要使用占位符“begin tijd”设置下一个输入字段的值。

<mat-form-field>
  <mat-label>Type behandeling</mat-label>
     <mat-select [(ngModel)]="data.cure" >
       <mat-option *ngFor="let typeCure of typeCures" [value]="typeCure.value">
            {{typeCure.viewValue}}
        </mat-option>
     </mat-select>
 </mat-form-field>

      <mat-form-field>
          <input matInput type="time" placeholder="Begin tijd" [(ngModel)]="data.begin">
      </mat-form-field>

例如,如果选择字段的值为“Sittard”,则输入字段的值必须为“13:00”。

有没有人可以帮我解决这个问题?谢谢!

【问题讨论】:

    标签: angular angular-material2 angular-forms


    【解决方案1】:

    你可以这样试试

    HTML

     <mat-form-field>
      <mat-label>Type behandeling</mat-label>
      <mat-select [(ngModel)]="data.cure" >
        <mat-option *ngFor="let typeCure of typeCures" [value]="typeCure.value" (selectionChange)="doSomething(typeCure.value)">
             {{typeCure.viewValue}}
         </mat-option>
      </mat-select>
     </mat-form-field>
    
      <mat-form-field>
          <input matInput type="time" placeholder="Begin tijd [(ngModel)]="selectedValue">
      </mat-form-field>
    

    TS

      selectedValue: any;
      doSomething(data) {
       this.selectedValue = data;
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2017-12-10
      • 2023-03-15
      相关资源
      最近更新 更多