Console Form Value

createPost(input: HTMLInputElement) {
    let post = { title: input.value };
    input.value = ''; // Clear the input after use

    this.http.post(this.url, post).subscribe((response) => {
      console.log(response);
    });
 }

HTML

<input
  #inputRef
  (keydown.enter)="createPost(inputRef)"
  type="text"
  class="form-control mb-3"
/>
Was this page helpful?