如何在p-autoComplete聚焦时显示建议

时间:2017-04-21 19:37:39

标签: javascript angular autocomplete primeng

我正在使用PrimeNG

中的primefaces.org

一切都运作良好。但我有一个小问题。使用p-autoComplete时,如果p-autoComplete处于焦点,则不会显示建议。我的意思是我必须输入一些东西来获得建议。我认为这是默认行为。但我想改变它。

我尝试了什么:

我试图设置[minLength]="0",但没有运气!!!!!!!!

3 个答案:

答案 0 :(得分:0)

您需要将一些默认项目设置为投标属性

<p-autoComplete [(ngModel)]="val" [suggestions]="results" field="name"></p-autoComplete>

你应该在组件代码中使用

results = ['a', 'b']

从服务加载时,您需要清除或附加到同一个数组

答案 1 :(得分:0)

您可以转到autocomplete.js文件并将一些代码添加到onInputFocus中,如下所示

    AutoComplete.prototype.onInputFocus = function (event) {
    this.focus = true;
    var queryValue = this.multiple ? this.multiInputEL.nativeElement.value : this.inputEL.nativeElement.value;
    if (this.dropdownMode === 'blank')
      this.search(event, '');
    else if (this.dropdownMode === 'current')
      this.search(event, queryValue);
    this.onDropdownClick.emit({
      originalEvent: event,
      query: queryValue
    });
    this.onFocus.emit(event);
};

你可以右键点击p-autoComplete让你到那里,小心更新,当你更新prime-ng时你将不得不再次这样做。

答案 2 :(得分:0)

这对我有用。

(onFocus)=“ autoComplete.handleDropdownClick()”

相关问题