[英]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
只有on
和off
两个值。 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.