【问题标题】:In Angular 7 - how can I disabled chrome auto fill and manage password select list在 Angular 7 中-如何禁用 chrome 自动填充和管理密码选择列表
【发布时间】:2020-03-18 06:20:24
【问题描述】:

在 Angular 7 中 - 如何禁用 chrome 自动填充和管理密码选择列表?

我尝试过的事情:

  • autocomplete="关闭"
  • autocomplete="假"

这是我的表格:

<form class="col-12" [formGroup]="form" autocomplete="off" (ngSubmit)="onSubmit()">

  <label>Email*</label>
  <input type="email" formControlName="email" placeholder="" class="col-12 mb1 field">    

  <label>Password*</label>
  <input type="password" formControlName="password" placeholder="" class="col-12 mb1 field">

  <label>Confirm Password*</label>
  <input type="password" formControlName="confirmPassword" class="col-12 mb2 field">


  <button type="submit" [disabled]="!form.valid" class="btn btn-primary col-12" prevent-double-submit>Get Started</button>
</form>

【问题讨论】:

标签: angular google-chrome angular6 angular7


【解决方案1】:

试试这个古老但有效的解决方案 - autocomplete="new-password"

Chromium Issue 370363 reference

Stack overflow reference

【讨论】:

  • 我只想在我的所有表单及其字段类型上关闭 chrome 自动填充
  • 这个解决方案有效吗? autocomplete="new-password"
  • 但是如果是无密码输入呢?
【解决方案2】:

你可以通过两种方式解决这个问题,

1) 在您的 HTML 中设置 autocomplete=null。

2) 如果你对在 HTML 中使用 null 不感兴趣,你需要创建一个指令。

ng g d Autocomplete

并修改 AutocompleteDirective 类如下:

private element: HTMLInputElement;
  constructor(private elRef: ElementRef) {
  this.element = elRef.nativeElement;
}
ngOnInit() {
  this.element.autocomplete = null //this will override default autocomplete.
}

在你的模板中:

<input appAutocomplete type="email" formControlName="email" placeholder="" class="col-12 mb1 field">

【讨论】:

  • 奇怪,你用的是哪个 Angular 版本?
  • 我想我犯了一个错误。更正并上传here。
  • 我正在使用 Angular 7
猜你喜欢
  • 1970-01-01
  • 2020-10-29
  • 2020-08-30
  • 2019-07-12
  • 2020-06-01
  • 2019-09-11
  • 2014-05-14
  • 2017-03-05
  • 1970-01-01
相关资源
最近更新 更多