1

While looking for a way to disable Chrome autofill (link) I noticed that if instead of creating an input like this:

<input name="address" [(ngModel)]="address />

I create it like this:

<input **data-name**="address" [(ngModel)]="address />

The name of the ngModel control is still correctly set when I access it from the typescript class. For example:

this.ngModel.name // outputs "address"

Which means the form still works fine, even if I have not set the name attribute explicitly.

The question is, why is this working? is it intended behaviour? Doing this effectively disables the Chrome autofill (as there is no name attribute), but I'm afraid this might be a weird coincidence that it may be fixed in the future and break my form.

Marc M.
  • 610
  • 1
  • 7
  • 13
  • So, you just want to remove chrome auto-fill? If so, can't you just place the input in a form and add `autocomplete="off"`, no need for `name` – DevEng Jul 30 '18 at 20:59
  • it is funny, because I just tried to do it in a plunker and the autocomplete="off" works, however, when I try on my project, the autocomplete="off" is completely ignored... – Marc M. Jul 30 '18 at 21:27
  • I know chrome has flip flopped on obeying the autocomplete rule, don't know where they stand now. With our app we use chrome but also Angular Material and never have the issue. (we have `autocomplete="off"` on all our forms) What if you try Firefox? – DevEng Jul 31 '18 at 02:30

0 Answers0