[英]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:例子:
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.