Search code examples
angularinputautocomplete

Angular input element autocomplete attribute value based on variable


I have an input element in my HTML and I want to set the native autocomplete HTML attribute value based on a variable in my TS file in an Angular component.

<input [autocomplete]="disableAutocomplete ? 'off' : 'on'">

ts:

disableAutocomplete: boolean;

I get an error in my HTML saying: "Property autocomplete is not provided by any applicable directives nor by textarea element".

How can I bind a variable value to this autocomplete attribute?


Solution

  • Try this syntax:

    <input [attr.autocomplete]="disableAutocomplete ? 'off' : 'on'">
    

    https://angular.io/guide/attribute-binding