关闭 primeNG 中芯片组件的自动完成功能

问题描述 投票:0回答:1

有没有人找到一种简洁的方法来关闭 primeNG 中 p-chips 组件的浏览器自动建议?或者更好的是关闭整个应用程序的自动建议。对于简单的输入字段,这有效:

<input [autocomplete]="'off'"/>

我希望 p 芯片有类似的东西,但不幸的是这似乎不起作用:

<p-chips [autocomplete]="'off'"></p-chips>
angular primeng autosuggest
1个回答
0
投票

我的解决方案是使用 ViewChild 装饰器引用 p-chips 组件内的输入元素,然后将自动完成属性设置为关闭。在我的 .ts 文件中:

import { AfterViewInit, Component, OnDestroy, ViewChild } from '@angular/core';
import { Chips } from 'primeng/chips';

@Component({
  selector: 'app-chips-wrapper',
  templateUrl: './chips-wrapper.component.html',
  styleUrls: ['./chips-wrapper.component.scss']
})
export class ChipsWrapper implements AfterViewInit {
  @ViewChild(Chips) chips: any;

  ngAfterViewInit(): void {
    if (this.chips) {
      const inputText = this.chips?.inputViewChild?.nativeElement;
      inputText?.setAttribute('autocomplete', 'off');
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.