- I want to take count of words, as user types in the textarea
- If he/she crosses more than 100 words he/she should not be allowed to type.
- I need to dynamically display word count as he/she types
sample.component.ts
wordCounter(){
this.wordCount = this.text ? this.text.split(/\s+/) : 0;
this.words=this.wordCount ? this.wordCount.length:0;
}
This is my function to count words
sample.component.html
<textarea [(ngModel)]="text" ng-change="wordCounter()" id="wmd-input" name="post-text" class="wmd-input s-input bar0 js-post-body-field processed" data-post-type-id="2" cols="92" rows="15" tabindex="101" data-min-length="" oncopy="return false;" onpaste="return false;" oncut="return false;"></textarea>
<div>Words:<span id="wordCount">{{ words }}</span></div>
This is my html code Please guide me in doing this. Thanks in advance