0

I have reference to input element:

  @ViewChild("inputSearch", {
    static: false
  })

Template is:

<input tabindex="0" type="text" (keydown)="keydownInputSearch($event)" #inputSearch autocomplete="off" autofocus />
<div class="searchWrapperBtn" (click)="reset()"></div>

Where reset is:

 public reset(): void {
    this.inputSearch.nativeElement.value = "";
  }

Why after reset() input value it is empty in input element but present in {{inputSearch.value}}

5
  • Can you please reproduce it in stackblitz? Commented Feb 21, 2020 at 15:43
  • Why are you directly interacting with the DOM when you have Angular data binding? Commented Feb 21, 2020 at 15:45
  • Do you mean to use ngModel? Commented Feb 21, 2020 at 15:45
  • @OPV you can use template-driven and reactive-from both. Commented Feb 21, 2020 at 16:37
  • I know but why in this case does not work Commented Feb 21, 2020 at 16:42

1 Answer 1

1

You are not calling view child properly, you chould do this

 @ViewChild('inputSearch', { static: false}) inputSearch: ElementRef;

Please take a look at this stackblitz

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.