PrimeNG:p-autoComplete 不清除值

PrimeNG: p-autoComplete not clearing value

我正在使用 PrimeNG。我写的自动完成代码如下

<p-autoComplete name="searchSuggestions" [(ngModel)]="suggestion" 
(completeMethod)="searchSuggestions($event)" [suggestions]="searchSuggestionsResult" field="field"></p-autoComplete>

我在方法中清除 suggestion,但不清除自动完成输入值。仅当我 select 从建议中清除时才会清除。

this.suggestion = undefined;

请将您的 primeng 版本升级到 "primeng": "^1.1.1",这样也能正常工作。

使用 onClear() 方法并设置您的模型值 = null。

====HTML

(onClear)="clearValue()

==ts

clearValue()
{
    this.suggestion = null;
}

仅当您从 auto-complete 列表中清除所有值时才会调用此函数。

希望这能奏效!!