angular4-forms - Angular 4 与 Material 2 的 react 形式,禁用自动完成

标签 angular4-forms

我正在使用 Angular cli、Angular 4 和 Angular Material 2。我需要禁用 chrome 自动完成功能,但我无法执行此操作。

我已经搜索并发现我需要在表单和输入中添加 autocomplete=off 或 autocomplete=false 。我还通过添加 type="search"找到了解决方法。它们似乎都不起作用。

Material 或角度是否凌驾于本说明之上?

我正在使用响应式(Reactive)表单!

有什么建议吗?

预先感谢您的帮助

最佳答案

Chrome 不再支持 autocomplete="off"(Chrome 在 34.0 中停止支持此功能)。请改用 autocomplete="new-password"。 你可以查看 Mozilla 的文档 here

来自文档:

For this reason, many modern browsers do not support autocomplete="off" for login fields:

If a site sets autocomplete="off" for username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page. This is the behavior in Firefox (since version 38), Google Chrome (since 34), and Internet Explorer (since version 11).

If an author would like to prevent the autofilling of password fields in user management pages where a user can specify a new password for someone other than themself, autocomplete="new-password" should be specified, though support for this has not been implemented in all browsers yet.

示例:

<mat-form-field *ngIf="filter.editorType==='text'">
    <input matInput autocomplete="new-password"
    [formControlName]="filter.id" 
    [placeholder]="filter.name" 
    (keyup.enter)="onApplyFiltersKeyboard()">
</mat-form-field>

关于angular4-forms - Angular 4 与 Material 2 的 react 形式,禁用自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48010470/

相关文章:

Angular 4模板驱动形式 - 从一个字段标记第二个作为触摸

angular - 当焦点从 Angular 输入中移出时触发验证?

html - 未找到带有定位器的机器人框架元素

javascript - 在 Angular 4 中使用发布请求时出现 400 错误

angular - 自定义控件中的 setValidators 没有 Angular 中的引用

javascript - 多个输入字段之间的表单验证

angular2-template - 当未在NgIf中呈现时,删除角度4中的验证

Angular 2 Reactive Forms 问题如何以 Angular 方式而不是 jquery 方式进行

Angular 5 - 表单验证电子邮件

angular - 通过按 Angular 4 中的回车键提交表单