【问题标题】:clicking on angular mat-chip selected not firing valueChanges and chip value is not available in valueChanes event单击 angular mat-chip 选择不触发 valueChanges 和芯片值在 valueChanes 事件中不可用
【发布时间】:2020-08-01 23:18:10
【问题描述】:

我有一个包含多个 mat-chips 的 mat-chip-list。但是当我点击 mat-chip 时,它们不会触发 valueChanges 事件,而其他控件触发的 valueChanges 事件也没有选择筹码的值。

这是代码。

<mat-chip-list aria-label="{{question.key}} selection" [selectable]=true>
                    <ng-container *ngFor="let opt of question.options">
                      <ng-container [ngSwitch]="opt.value">
                        <ng-container *ngSwitchCase="'No'">
                          <mat-basic-chip class="mat-basic-chip-no" [value]="opt.key" #lbl="matChip"
                            (click)="chipControlOnSelect(question.key,opt.key,fi,fgi, lbl)">
                            {{opt.value}}</mat-basic-chip>
                        </ng-container>
                        <ng-container *ngSwitchDefault>
                          <mat-basic-chip [value]="opt.key" #lbl="matChip"
                            (click)="chipControlOnSelect(question.key,opt.key,fi,fgi, lbl)">
                            {{opt.value}}</mat-basic-chip>
                        </ng-container>
                      </ng-container>
                    </ng-container>
                  </mat-chip-list>

【问题讨论】:

  • 你有没有试过像这样[(ngModel)] = ''modelname"
  • 应该提到,这些控件都是模板形式的。

标签: angular angular-material


【解决方案1】:
(click)="chipControlOnSelect(opt.key)"
[value]="opt.key"

在上面的语句中,可能有以下变化可以帮助获取值。

(click)="chipControlOnSelect($event)"
[value]="opt.newkey" 

将所有参数(question.key、opt.key、fi、fgi、lbl)与管道符号组合起来,并将其存储在'opt.newKey'中

chipControlOnSelect(event: any){
  let newKey = event.target.value;
  --- here you can split the values by using pipe symbol and get the required values.

}

【讨论】:

  • 但我需要表单的 valueChange 事件中的值
猜你喜欢
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
  • 1970-01-01
  • 2021-06-30
  • 2019-06-09
  • 2022-11-10
  • 2023-01-21
  • 1970-01-01
相关资源
最近更新 更多