angular - 如何防止按钮形成Angular?
问题描述
我有一个搜索表格:
<form class="navbar-form">
<div class="input-group no-border">
<input type="text" #term class="form-control" (keyup.enter)="search()" placeholder="поиск..." />
<button class="btn btn-white btn-round btn-just-icon" (click)="search()">
<i class="material-icons">search</i>
<div class="ripple-container"></div>
</button>
</div>
</form>
它应该按click
and搜索key.enter
:
search(): void {
const value = this.term.nativeElement.value ? this.term.nativeElement.value.toString().trim() : null;
this.router.navigate(['search?=' + value]);
问题是当我单击按钮时它会重新加载页面。我也不喜欢条件const value = this.term.nativeElement.value ? this.term.nativeElement.value.toString().trim() : null;
我该如何改进它?
我试图通过$event
:search($event)
。
search(e) {
e.eventPrevent();
}
它对我不起作用。
解决方案
它应该是:
e.preventDefault();
推荐阅读
- javascript - 输入选择器将 jquery 代码转换为 javascript 问题
- python - Scrapy,从 ICML 抓取论文
- ionic4 - 从相机或图库上传图像
- c - 将带十六进制的无符号整数转换为字符串
- .net - 移动项目时 Visual Studio Nuget 程序集引用损坏
- wordpress - WordPress为用户添加访问权限以编辑他的评论
- java - 使用 maven 从类中运行 main
- xcode - Xcode viewcontroller.swift 中的颜色约定是什么?
- python - 无法使用 QWebEnginePage::runJavaScript() 更改 backgroundImage
- android - 如何解决 Flutter 应用上的 Google Play 未优化 APK 问题?