Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为什么重置后输入值为空?_Angular_Angular6_Angular8 - Fatal编程技术网

Angular 为什么重置后输入值为空?

Angular 为什么重置后输入值为空?,angular,angular6,angular8,Angular,Angular6,Angular8,我引用了输入元素: @ViewChild("inputSearch", { static: false }) 模板为: <input tabindex="0" type="text" (keydown)="keydownInputSearch($event)" #inputSearch autocomplete="off" autofocus /> <div class="searchWrapperBtn" (click)="reset()"></

我引用了输入元素:

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

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

为什么在
reset()
输入值之后,它在输入元素中为空,但在
{{inputSearch.value}

中出现,您没有正确调用view child, 你可以这样做

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

请看一看这个

你能在stackblitz中复制它吗?当你有角度数据绑定时,为什么你直接与DOM交互?你的意思是使用ngModel吗?@OPV你可以同时使用
模板驱动的
反应式的
。我知道为什么在这种情况下不起作用
 @ViewChild('inputSearch', { static: false}) inputSearch: ElementRef;