Html 如何使文本以小写形式返回

Html 如何使文本以小写形式返回,html,angular,typescript,filter,angular-material,Html,Angular,Typescript,Filter,Angular Material,我有一个输入,用户可以在按下enter键时搜索一个芯片并返回一个匹配的芯片,但我想知道如何使输入在按下enter键后始终返回小写,因为一段时间看起来用户可以创建两个不同的芯片,一个使用大写字母,另一个使用小写字母,即使它只存储小写字母 比如说现在, 用户用大写字母输入“图表->创建“图表”芯片->刷新浏览器后,以小写字母“图表”显示 用户用小写字母输入“图表->创建“图表”芯片->刷新浏览器后,以小写字母“图表”显示 此外,如果用户先用大写字母创建芯片,看起来他们可以多次创建同一芯片,但如果他们

我有一个输入,用户可以在按下enter键时搜索一个芯片并返回一个匹配的芯片,但我想知道如何使输入在按下enter键后始终返回小写,因为一段时间看起来用户可以创建两个不同的芯片,一个使用大写字母,另一个使用小写字母,即使它只存储小写字母

比如说现在,

用户用大写字母输入“图表->创建“图表”芯片->刷新浏览器后,以小写字母“图表”显示

用户用小写字母输入“图表->创建“图表”芯片->刷新浏览器后,以小写字母“图表”显示

此外,如果用户先用大写字母创建芯片,看起来他们可以多次创建同一芯片,但如果他们先用小写字母创建芯片,输入会阻止用户多次创建同一芯片,这就是我想要的

正在尝试做的事

我只想创建一个芯片,如果用户输入小写或大写,并防止他们试图创建相同的芯片再次大写或小写

HTML


这和我的项目一模一样
但也有同样的问题,用户可以用同一个单词创建多个标签,比如“Apple”、“Apple”、“Apple”,而不是一个。

尝试在HTML文件中使用小写管道


尝试在HTML文件中使用小写管道


检查代码和注释

  add(event: MatChipInputEvent): void {
           const input = event.input;
           const value = event.value.toLowerCase(); //<--first to lowerCase

            // Better use findIndex
           const index=this.allFruits.findIndex((f) => f.toLowerCase() ===value)
           if (index>=0) { 
             this.fruits.push(this.allFruits[index]); //<--push the element of
                                                      // allFruits, not the "value"
             this.allFruits.splice(index,1)  //remove the fruit of the list
           }  

    // Reset the input value
    if (input) {
      input.value = '';
    }

    this.fruitCtrl.setValue(null);
  }
添加(事件:MatchiPiInputEvent):无效{ 常量输入=event.input; const value=event.value.toLowerCase();//f.toLowerCase()==value) 如果(索引>=0){
this.fruits.push(this.allFruits[index]);//检查代码和注释

  add(event: MatChipInputEvent): void {
           const input = event.input;
           const value = event.value.toLowerCase(); //<--first to lowerCase

            // Better use findIndex
           const index=this.allFruits.findIndex((f) => f.toLowerCase() ===value)
           if (index>=0) { 
             this.fruits.push(this.allFruits[index]); //<--push the element of
                                                      // allFruits, not the "value"
             this.allFruits.splice(index,1)  //remove the fruit of the list
           }  

    // Reset the input value
    if (input) {
      input.value = '';
    }

    this.fruitCtrl.setValue(null);
  }
添加(事件:MatchiPiInputEvent):无效{ 常量输入=event.input; const value=event.value.toLowerCase();//f.toLowerCase()==value) 如果(索引>=0){
this.fruits.push(this.allFruits[index]);//我想小写的管道解决了这个问题。我刚刚运行了这个项目,它对我来说很好

    <mat-form-field class="demo-chip-list">
  <mat-chip-list #chipList>
    <mat-chip
      *ngFor="let fruit of fruits"
      [selectable]="selectable"
      [removable]="removable"
      (removed)="remove(fruit)">
      {{ fruit | lowercase }}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>
    <input
      placeholder="New fruit..."
      #fruitInput
      [formControl]="fruitCtrl"
      [matAutocomplete]="auto"
      [matChipInputFor]="chipList"
      [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
      [matChipInputAddOnBlur]="addOnBlur"
      (matChipInputTokenEnd)="add($event)"
    />
  </mat-chip-list>
  <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
    <mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
      {{ fruit | lowercase }}
    </mat-option>
  </mat-autocomplete>
</mat-form-field>

{{水果|小写}}
取消
{{水果|小写}}

我想小写的管道解决了这个问题。我刚刚运行了这个项目,它对我来说很好

    <mat-form-field class="demo-chip-list">
  <mat-chip-list #chipList>
    <mat-chip
      *ngFor="let fruit of fruits"
      [selectable]="selectable"
      [removable]="removable"
      (removed)="remove(fruit)">
      {{ fruit | lowercase }}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>
    <input
      placeholder="New fruit..."
      #fruitInput
      [formControl]="fruitCtrl"
      [matAutocomplete]="auto"
      [matChipInputFor]="chipList"
      [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
      [matChipInputAddOnBlur]="addOnBlur"
      (matChipInputTokenEnd)="add($event)"
    />
  </mat-chip-list>
  <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
    <mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
      {{ fruit | lowercase }}
    </mat-option>
  </mat-autocomplete>
</mat-form-field>

{{水果|小写}}
取消
{{水果|小写}}

您应该首先确定芯片的命名方式,即小写、titlecase或大写。现在确定了芯片的命名方式后,您可以在创建芯片之前将其转换为所需的大小写。我只希望芯片的命名始终使用小写,即使用户键入大写。例如,即使用户键入“图表”然后按enter键,它仍将以小写形式显示。我只是认为这可能是一个解决方案,可以防止用户创建诸如“图表”、“图表”、“图表”、“图表”等。等等,必须使用javascripts string.toLowerCase()提交函数中的函数我尝试了value.toLowerCase;我不能再为同一个芯片创建重复标记,但我仍然能够创建所有这些“图表”、“图表”、“图表”、“图表”…任何建议您应该首先确定芯片的命名方式,即小写、titlebase或大写。现在确定了芯片的命名方式后,您可以在创建芯片之前将其转换为所需的大小写。我只希望芯片的命名始终使用小写,即使用户键入大写。例如,即使用户键入“CHART”并按enter键,它仍将以小写形式显示。我只是认为这可能是一个解决方案,可以防止用户创建诸如“CHART”、“CHART”、“CHART”、“CHART”等。等等必须使用javascripts string.toLowerCase()提交函数中的函数我尝试了value.toLowerCase;我不能再为同一个芯片创建重复标记,但我仍然能够创建所有这些“图表”、“图表”、“图表”、“图表”…任何建议都不起作用…因为我在输入中显示芯片,所以我不确定将其放置在何处。在示例中,它放置在标记中,而不是输入:(…请您检查一下……这是我的项目的外观,并且它能够创建“Apple”“Apple”“apPPLe”而不仅仅是一个。仍然不工作…因为我在输入上显示芯片,我不确定该放在哪里。在示例中,它放在标记中,而不是输入:(…请你检查一下……这是我的项目的外观,并且它能够创建“Apple”“Apple”“apPPLe”而不是一个。谢谢你,真的很感激:)谢谢你,真的很感激:)