在Angular 8中禁用输入下拉列表的自动填充,可以通过以下步骤实现:
autocomplete
属性,并将其值设置为off
,如下所示:<input type="text" autocomplete="off">
ViewChild
装饰器获取到输入框的引用,并在ngAfterViewInit
生命周期钩子中禁用自动填充,如下所示:import { Component, ViewChild, AfterViewInit } from '@angular/core';
@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html',
styleUrls: ['./your-component.component.css']
})
export class YourComponent implements AfterViewInit {
@ViewChild('inputField') inputField: ElementRef;
ngAfterViewInit() {
this.inputField.nativeElement.setAttribute('autocomplete', 'off');
}
}
#inputField
指令为输入框创建一个引用,如下所示:<input type="text" #inputField>
这样就可以在Angular 8中禁用输入下拉列表的自动填充了。
关于Angular的更多信息和使用方法,你可以参考腾讯云的产品介绍页面:Angular。
领取专属 10元无门槛券
手把手带您无忧上云