所以当我按回车键时我的代码就可以工作(它运行performSearch
函数成功),但是当我尝试通过点击提交按钮运行该函数时,出现错误:
无法读取未定义的属性错误
这是我的代码:
<mat-form-field (ngSubmit)='performSearch($event)' color='primary' id='search-input' class='full-width' appearance='outline'>
<mat-label color='red'>Search</mat-label>
<input #searchBar matInput [(ngModel)]='searchValue' name='searchBar' [value]='searchValue' (keyup.enter)='performSearch($event)'>
</mat-form-field>
<button mat-raised-button color="primary" (click)='performSearch(searchBar.value)' id='submit-search' type='submit' for='searchBar'>Submit</button>
我想要的只是一种抓住的方法#searchBar
' 值并将其传递到performSearch()
当我单击按钮时触发的函数。我怎么做?
您正在搜索栏中进行两种方式绑定var searchValue
所以你只需要在点击提交时更改传递这个变量。
只需替换您的点击事件即可
(click)='performSearch(searchBar.value)' to
(click)='performSearch(searchValue)'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)