Sahin
Sahin

Reputation: 97

How to disable browser autocomplete on angular form field?

I have a login page, i want to stop autocomplete and auto fills in my form page.

By using autocomplete="off" auto fill Stopped. But autocomplete still load when i click the input fields (password or user name fields). how to stop this autocomplete ?

I tried the following methods, autocomplete="off", autocomplete="false", autocomplete="new-password" but still it came.

My sample code :

<form #f="ngForm" autocomplete="off">
  <mat-form-field floatLabel="auto">
    <mat-label>User name</mat-label>
    <mat-icon matPrefix>person</mat-icon>
    <input matInput 
           tabindex="1" 
           #username="ngModel"
           [(ngModel)]="userName" 
           required 
           name="username"
           maxlength="100" 
           autocomplete="off" 
           role="presentation">
  </mat-form-field>
  <mat-form-field floatLabel="auto">
    <mat-label>Password</mat-label>
    <mat-icon matPrefix>lock</mat-icon>
    <input matInput 
           tabindex="2" 
           [(ngModel)]="password" 
           required 
           name="password" 
           #pass="ngModel" 
           type="password" 
           maxlength="100"
           autocomplete="new-password" 
           role="presentation">
  </mat-form-field>
</form>

Google chrome version: Version 76.0.3809.100 (Official Build) (64-bit)

Upvotes: 0

Views: 2782

Answers (2)

Ankit
Ankit

Reputation: 162

autocomplete="new-password" this worked for me. Other values like false, off, randomstring didn't work.

Upvotes: 0

Add "anystring" on autocomplete and a random name to tag.

autocomplete="anyrandomstring" name="test"

Upvotes: 5

Related Questions