简体   繁体   English

如何在输入字段中禁用自动完成功能:Angular

[英]How to disable Autocomplete in input fields : Angular

I have a reactive form where i am using input fields.我有一个反应式表单,我在其中使用输入字段。 I want to disable autocomplete feature for input types for any kind of browser.我想为任何类型的浏览器禁用输入类型的自动完成功能。 I have tried autocomplete="off" in both input's and form level.我在输入和表单级别都尝试过 autocomplete="off" 。 But it is not working.但它不起作用。

How to create a Angular directive for disabling autocomplete for all browsers.如何创建一个 Angular 指令来禁用所有浏览器的自动完成。 here is the code that I am using -这是我正在使用的代码 -

<form autocomplete="off" [formGroup]="registration" (ngSubmit)="registerOnSubmit()">
  <div>
    <input type="text" name="firstName" id="firstName" autocomplete="off" formControlName="firstName" />
    <label>Name</label>
  </div>
  <div>
    <input type="text" name="lastName" id="lastName" autocomplete="off" formControlName="lastName" />
    <label>Name</label>
  </div>
  <button>submit</button>
</form>

According to this: Turning_off_form_autocompletion |据此: Turning_off_form_autocompletion | Developers - Mozilla . 开发人员 - Mozilla

If a browser keeps on making suggestions even after setting autocomplete to off, then you have to change the name attribute of the input element.如果浏览器在将自动完成设置为关闭后仍继续提供建议,那么您必须更改 input 元素的 name 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM