【问题标题】:Prevent Mat-chip from adding row after selection防止 Mat-chip 在选择后添加行
【发布时间】:2021-07-27 04:10:59
【问题描述】:

我试图阻止 mat-chip 模块在选择一个芯片后自动添加一行。最大筹码数为 1,因此我在用户从下拉列表中选择一个项目后禁用输入。但是,它仍然在其下方添加一行,就好像他们可以输入更多内容一样。我怎样才能防止这种情况发生?

  <mat-chip-list #chipList aria-label="Fruit selection"  >
    <mat-chip
      *ngFor="let item of selected; let i = index"
      [selectable]="!disabled"
      [removable]="!disabled"
      (removed)="remove(i)">
      {{item[filterProperty]}}
      <mat-icon matChipRemove>cancel</mat-icon>
    </mat-chip>
    <input
    [maxLength]="maxLength"
      [value]="optionBaseValue"
      [placeholder]="label" #chipsInput
      [disabled]="(selected.length === maxCount) || inEditMode === false"
      [matAutocomplete]="auto"
      [matChipInputFor]="chipList"
      [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
      [matChipInputAddOnBlur]="addOnBlur"
      (focus)="autoInputValue($event)"
      (focusout)="resetAutoInputValue($event)"
      (matChipInputTokenEnd)="add($event)">
  </mat-chip-list>
  <mat-autocomplete #auto="matAutocomplete" (optionSelected)="itemSelected($event)" (onBlur)="itemSelected($event)">
    <mat-option *ngFor="let item of filteredItems | async " [value]="item">
      <div > {{item[filterProperty]}}</div>
    </mat-option>
  </mat-autocomplete>

谢谢!!

【问题讨论】:

  • 可能是&lt;input [hidden]="selected.length === 1" 之类的?
  • 这能解决问题吗?
  • 好的,谢谢!只是将条件更改为> 0。效果很好

标签: html angular typescript angular-material material-ui


【解决方案1】:

你可以使用类似的东西:

<input [hidden]="selected.length === 1"

请注意,您可以随意更改条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 2019-01-08
    相关资源
    最近更新 更多