The Task here is to make sure that the user enters enough words in the Textarea. The button will be enabled or disabled on the basis of the word count entered by the client or user. Here the word limit will be set by admin of the project or Application. If word count lies between the parameter set by Admin then the button will remain enabled. If word count exceeds the limit or is less than the limit then it will remain disabled.
Example: In this approach, we have set parameters to word count between 5 words to 20 words.
- Here, word count is 1 which is not in 5-20 word range hence button will be disabled.
Input : GeeksforGeeks Output: Button will be disabled
- Here, word count is 5 so now button will be enabled.
Input : Hello Geek! welcome to GeeksforGeeks!! Output: Button will be enabled
For reaching the goal we will use InputEvent. That will help us to get a count of words after the input of every character. It is an Angular event binding to respond to any DOM event. It is an asynchronous event that is triggered as the user is interacting with the text-based input controls.
Below all the steps are mentioned oreder-wise:
Implementation Example:
- txtxhk.component.html:
<textarea(input)="CheckLen($event)"id="ta"></textarea><br><buttonid="bt"disabled={{check}}>Button</button>chevron_rightfilter_none - txtxhk.component.ts:
import { Component, OnInit } from'@angular/core';@Component({selector:'app-txtchk',templateUrl:'./txtchk.component.html',styleUrls: ['./txtchk.component.css']})export class TxtchkComponent implements OnInit {c=0;//defined counterconstructor() { }check;//defined check variablengOnInit(): void {}//value of textarea is taken from eventCheckLen(event){// c counts the number of words of input valuethis.c=event.target.value.split(' ').length;// We have set that minimum word count should// be 5 or more and the maximum should be 20.if(this.c<5 ||this.c>20){this.check=true;}if(this.c<=20 &&this.c>=5){this.check=null;}}}chevron_rightfilter_none
Output: Start the Development server and enter words in textarea to see whether the button goes enabled or disabled on particular outputs. Here are few output Examples with word count values logged on console.
- The button is disabled because the words are less than 5.

- The button is enabled in this case because the words are more than 5 and less than 21.

- The button is disabled because the words are more than 20.
Recommended Posts:
- How to make sure that Apache service keeps running in Ubuntu
- AngularJS | textarea Directive
- How to stop submit button from expanding along with textarea?
- How to make textarea 100% without overflow when padding is present ?
- How to get the value of radio button using AngularJS ?
- How to trigger HTML button after hitting enter button in textbox using JavaScript ?
- How to create a radio button similar to toggle button using Bootstrap ?
- How to add input fields dynamically on button click in AngularJS ?
- How to replace all words with another words in HTML ?
- How to disable resizable property of textarea using CSS?
- How to create auto-resize textarea using JavaScript/jQuery ?
- How to change the shape of a textarea using JavaScript?
- How to change the Content of a <textarea> using JavaScript ?
- How to set textarea scroll bar to bottom as a default using JavaScript/jQuery ?
- How to disable arrow key in textarea using JavaScript ?
- button tag vs input type="button" attribute
- How to make horizontal line with words in the middle using CSS?
- HTML | DOM Textarea autofocus Property
- HTML | DOM textarea minlength Property
- HTML | DOM Textarea maxlength Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

