BrowserPreferences.SetChromiumSwitches("--lang=en-GB");
我正在使用<p-autoComplete [style]="{'width':'100%'}" name="searchSuggestions"
[(ngModel)]="suggestion" (completeMethod)="searchSuggestions($event)"
[suggestions]="searchSuggestionsResult" field="field"></p-autoComplete>
。在使用鼠标复制和粘贴文本时,模型值(建议)将作为未定义。如何从模型中获取粘贴值?
答案 0 :(得分:0)
将字符串复制并粘贴到p-autoComplete对我来说很好。我只想分享我的方法,希望你能找到它。
HTML:
<p-autoComplete [style]="{'width':'100%'}" name="searchSuggestions"
[(ngModel)]="suggestion" (completeMethod)="searchSuggestions(suggestion)"
[suggestions]="searchSuggestionsResult" field="field">
</p-autoComplete>
请注意,我将模型作为参数传递给completeMethod。
哦,顺便说一下,我使用了Angular 2的打字稿。
Ts:
searchSuggestions(suggestion) {
this.searchSuggestionsResult = [];
if(suggestion != "") {
var list = this.searchSuggestionsResult.filter(function(el) {
return (el) ? el.toLowerCase().startsWith(suggestion.toLowerCase()) : false;
});
list.sort((a,b) => a.toLowerCase().localCompare(b.toLowerCase());
list.forEach(element => {
this.searchSuggestionsResult.push(element);
});
} else {
this.searchSuggestionsResult = [];
}
}
希望它有所帮助!
答案 1 :(得分:0)
使用onClear()方法&amp;设置模型值= null
==== HTML
(onClear)="clearValue()"
== TS
clearValue()
{
this.searchSuggestionsResult = null;
}
只有清除了自动完成列表中的所有值后才会调用此函数。
希望这会有效!!