Search code examples
angulartypescriptangular2-template

Disable button if input length less than 3


I want to disable button if input length is less than 3:

 <input type="text" [(ngModel)]="newListItem">
 <button [disabled]="{ disabled : newListItem.length < 3 }"></button>

But this code doesn't work. How can I achieve my goal?


Solution

  • You only need to pass an expression to disabled property, there's no need to create object:

    <button [disabled]="newListItem.length < 3"></button>