Issue
I have a custom Angular input component that using a textarea
as it's input field.
How do I propagate the enter key event to the parent form?
Solution
You can create a custom event which will be send to the parent once your enter key event is received.
In your custom input element :
@Output() onEnterPressed:EventEmitter<any> = new EventEmitter<any>();
// Method called on KeyUp event. Using KeyUp as it recommended by Angular for Keyboard events.
handleKeyPressed(keyEvent:KeyboardEvent) {
if(enter_key_is_pressed) {
this.onEnterPressed.emit(keyEvent);
}
}
In parent component template:
<custom-input [onEnterPressed]="handleEnterEvent($event)"></custom-input>
In parent component component class:
handleEnterEvent(event:KeyboardEvent):void {
//do_whatever_you_want
}
Answered By - Ankit Kapoor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.