简体   繁体   English

如何在角度应用程序中启用表单自动完成

[英]How to enable form autocomplete in angular application

I migrated an app to Angular and now it does not autocomplete the form upon returning page visits. 我将应用程序迁移到Angular,现在返回页面访问后它不会自动完成表单。 Otherwise it works perfectly fine. 否则,它会很好地工作。

My gut feeling is that it has to do with the *ngIf template expressions and just the general non-static nature of Angular but I'm wondering if there's anything I can do to perhaps enable the form to autofill? 我的直觉是它与* ngIf模板表达式以及Angular的一般非静态性质有关,但是我想知道是否可以做些什么使表格自动填充?

login.component.html: login.component.html:

<div class="container">
  <div class="row">
    <div class="col">
      <hr>
      <form autocomplete="on">
        <div class="form-group">
          <input type="email" class="form-control" placeholder="Email address" name="email" required [(ngModel)]="email" autocomplete="email"/>
        </div>
        <div class="form-group">
          <input type="password" class="form-control" placeholder="Password" name="password" required [(ngModel)]="pass" />
        </div>
        <hr>
        <div class="form-group">
          <button (click)="Register()">Register</button>
          <button (click)="Login()">Sign In</button>
        </div>
      </form>
    </div>
  </div>
</div>

app.component.html: app.component.html:

<app-login *ngIf="!loggedIn"></app-login>

The input attriubte autocomplete has only two values on and off . 输入属性autocomplete只有onoff两个值。 To enable autocomplete you would want to use autocomplete="on" . 要启用自动完成功能,您需要使用autocomplete="on" Your code should look like the following: 您的代码应如下所示:

<input type="email" class="form-control" placeholder="Email address" name="email" required [(ngModel)]="email" autocomplete="on"/>

You have autocomplete set up properly as an html attribute of your input element, but you've set it equal to "email" , which is not a valid value. 您已经将autocomplete正确设置为input元素的html属性,但是将其设置为等于"email" ,这不是有效值。

Review the documentation on autocomplete . 查看有关自动完成文档

If you set autocomplete="on" your code will work. 如果将autocomplete="on"设置autocomplete="on"您的代码,则可以使用。

The code working with this change: https://jsfiddle.net/pdzb02yk/2/ 处理此更改的代码: https : //jsfiddle.net/pdzb02yk/2/

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

相关问题 有没有办法为 angular 反应形式启用自动完成功能? - Is there a way to enable the autocomplete for angular reactive form? 如何在角度表单字段上禁用浏览器自动完成功能? - How to disable browser autocomplete on angular form field? 如何在 Angular 的应用程序级别设置自动完成“关闭”? - How to set autocomplete “off” at application level in Angular? 如何在Hyperledger Angular应用程序中启用身份验证 - How to enable authentication in hyperledger Angular application 如何为Angular 6应用程序启用CSS源图? - How to enable CSS sourcemaps for Angular 6 application? 如何在 Angular 14 反应式表单中一次启用所有表单控件 - How to enable all form controls at once in an Angular 14 reactive form Angular 素材如何动态创建在同一个表单中添加多个自动完成 - Angular material How to create dynamically add multiple autocomplete in same form 如何扩展 Angular 表单指令以具有全局自动完成=“关闭” - How to extend Angular Form Directive to have globally autocomplete="off" 单击编辑按钮后,如何启用角度4中的表单字段? - How to enable the form fields in angular 4 after clicking on edit button? 如何为 Angular CLI 7 应用程序启用 js 文件压缩? - How do I enable js files compression for Angular CLI 7 application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM