0

Is this possible that I can set autocomplete "off" at any one place and it restricts all the inputs of the application in Angular(8 or Later)?

Gaurav Panwar
  • 974
  • 10
  • 11
  • 1
    Does this answer your question? [Is there a W3C valid way to disable autocomplete in a HTML form?](https://stackoverflow.com/questions/582244/is-there-a-w3c-valid-way-to-disable-autocomplete-in-a-html-form) – Elias Soares Jul 20 '21 at 17:49

1 Answers1

4

Using directive selector we can match all the input element. Then using HostingBinding we can set autocomplete off. In this way we don't need to apply directive on input element manully as it will be applied automatically.

import { Directive, HostBinding } from '@angular/core';

@Directive({
  selector: 'input'
})
export class InputDirective {
  @HostBinding('autocomplete') autocomplete = 'off';
  constructor() {}
}

Working Example

Chellappan வ
  • 23,645
  • 3
  • 29
  • 60