I have an Angular chat app that allows a user to fabricate chats. The app takes input, processes the input text when the submit button is clicked, refreshes with ngInit so the chats new message is displayed. However the input field continues to hold the previous message input. I want the input to be empty/clear every time the submit button is clicked.
<input #taskTitleInput class="input has-background-light is-medium" type="text"
placeholder="Enter message..."><br>
(click)="createLeftMessage(taskTitleInput.value)">Alice</button>
And here is the component function that adds the message to the chat.
createLeftMessage(title: string) {
if (typeof this.chatId === "string") {
this.chatService.createMessage(title, this.chatId, true).subscribe((newMessage: any) => {
console.log("added message to chat");
this.ngOnInit();
})
}
}
I have tried the following in the createLeftMessage function, but it does not recognize taskTitleInput.
taskTitleInput.value == '';
How can I have the input field cleared automatically every time the submit button is clicked?