Angular 材料:你能禁用输入的自动完成建议吗?

Angular Materials: Can you disable the autocomplete suggestions for an input?

我只是在使用像这样的简单输入容器

<md-input-container class="md-block" flex-gt-sm >
    <label>Name</label>
    <input md-maxlength="30" name="name" ng-model="name" />
</md-input-container>

输入字段提示之前输入的值,这会掩盖一些重要的界面元素,而且在我的情况下也确实没有必要。有什么方法可以禁用建议吗?

在输入元素中添加autocomplete="off",就像这样:

<input md-maxlength="30" name="name" ng-model="name" autocomplete="off" />

参见 this 以供参考。

以防万一有人和我有同样的经历(因为当前的答案对我的 chrome 不起作用),我像下面那样使用并且它起作用了:

<input md-maxlength="30" name="name" ng-model="name" autocomplete="new-password" />

新浏览器似乎会查看 id 字段或 name 字段以确定您要使用自动填充查找的内容。当我想关闭自动填充功能时,我开始倒着拼写。

问题标签 - 自动填充弹出窗口

<input id='cp_state_i' required />

修复 - 不自动填充弹出窗口

<input id='cp_etats_i' required />

我的问题是我正在为各州使用自动完成选项列表。弹出窗口是个问题。这是我的解决方法,可能对您有所帮助。

另一个似乎在某些文本字段上起作用的东西是这个

<input autocomplete='new-password'/>

我删除了 type='text,它就不会弹出任何东西了。但无论出于何种原因,它并没有对某些事情起作用。

我不确定为什么浏览器不再支持自动完成='off'。在处理 CRUD 和其他合理的操作时,除了简单的登录表单之外,它会让人头疼。

对于没有 name 属性 或将其值设置为通用的自动填充功能(姓名、电子邮件、街道、国家...)。

在我的例子中,将输入设置为一个不寻常的名称就足够了。

<input type="text" name="someUnusualName" autocomplete="off">
<input type="text" id="example" placeholder="" matInput  [(ngModel)]="item.productDescription" [matAutocomplete]="product" [matAutocompleteDisabled]="condition"/>

只需在有效条件下使用 [matAutocompleteDisabled] 属性。

将 autocomplete="off" 添加到输入,但对于现代浏览器使用 autocomplete="nope"

旧版浏览器

<input md-maxlength="30" name="name" ng-model="name" autocomplete="off" />

现代浏览器

<input md-maxlength="30" name="name" ng-model="name" autocomplete="nope" />

只要输入type="search"就可以了。在 Google Chrome 版本 92.0.4515.107(官方构建)(arm64)

上测试

例如:<input type="search" name="namesearch" id="search-cust" placeholder="Shop Name" style="width:170px" />