I have functionality where user types something and press submit button then the cursor should move to next line. When user types some words and press Enter key cursor should shift to next line with in the textarea. I am trying to achieve this functionality using KeyBoardEvent by using keypress event with keycode for Enter key. Below is the code, HTML code
<textarea #elRef id="language" class="post-text-area badge-post-textarea focus ng-pristine ng-
untouched ng-valid ng-empty" placeholder="Share your thoughts..." [(ngModel)]="content"></textarea>
<button (click)="submit()"></button>
The below angular code is where once user clicks submit I creating one keyevent for Enter and dispatch that event but Enter key event is not happening. ANGULAR JS code
@ViewChild('elRef', { static: false }) userInput: ElementRef;
submit(){
const event = new KeyboardEvent('keypress', { 'keyCode': 32 });
this.userInput.nativeElement.dispatchEvent(event);
return;
}
Kindly, Please some one help on this