简体   繁体   English

有 mat-autocomplete 不是替换而是增加价值

[英]have mat-autocomplete not replace but add value

I know that with the onSelectionChange() from the mat-option of the mat-autocomplete i can do something when an option is selected but what i want is for the autocomplete to ADD the value of the mat-option to the input instead of replace its content.我知道使用来自 mat-autocomplete 的 mat-option 的onSelectionChange()我可以在选择一个选项时做一些事情,但我想要的是自动完成将 mat-option 的值添加到输入而不是替换它的内容。

Example:例子:

  • input: "hello"输入:“你好”
  • click mat option " world"单击垫选项“世界”
  • input: "hello world"输入:“你好世界”

How do i accomplish this without kepping tabs on the form value and stocking its previous value and putting it back (since that just seems like a bad workaround)?我如何在不保留表单值标签并存储其先前值并将其放回原处的情况下完成此操作(因为这似乎是一个糟糕的解决方法)?

<mat-form-field class="w-100">
   <textarea [matAutocomplete]="auto" [value]="hello" matInput></textarea>
   <mat-autocomplete #auto="matAutocomplete" >
      <mat-option [value]="world">
         world
      </mat-option>
   </mat-autocomplete>
</mat-form-field>

My workaround is to always prepend the option value with the current input value我的解决方法是始终在选项值前面加上当前输入值

<mat-form-field class="w-100">
   <textarea [matAutocomplete]="auto" [value]="hello" matInput></textarea>
   <mat-autocomplete #auto="matAutocomplete" >
      <mat-option [value]="hello + ' ' + world">  <<=== modified 
         world
      </mat-option>
   </mat-autocomplete>
</mat-form-field>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM