Angular 2. 事件 Keyup 不适用于输入信号

这是一个非常简单的情况,但我真的不知道为什么它不起作用。 我收到了一个输入文本字段,应该在事件中调用函数 keyup. 但这不是。


<input "="" #search="" ="filtercatalogues="" class="form-control m-1" keyup="" search.value="" type="text"/>


我是代码本身。


filterCatalogues/value: string/: CataloguesListDto[] {
return this.catalogues.filter /catalogue => {
return catalogue.companyName === value || catalogue.catalogueName === value;
}/;
}
已邀请:

风见雨下

赞同来自:

您需要更改您的活动 filterCatalogues. 我建议

目录

绑在k。 dom


<input "="" #search="" ="filtercatalogues="" class="form-control m-1" keyup="" type="text"/>

filterCatalogues//{
this.catalogues = this.catalogues.filter /catalogue => {
return catalogue.companyName === searchModel|| catalogue.catalogueName === searchModel;
}/;
}

冰洋

赞同来自:

我用 angular 9.

以下示例也有效:


<input "="" #myinput="" ="dosearch="" keyup="" myinput.value="" placeholder="Search for data ..." type="text">


方法 doSearch 使用路由器使用找到的元素更新另一个分区:


import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component/{
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css']
}/
export class SearchComponent implements OnInit {

constructor/private router: Router/ { }

ngOnInit//: void {
}

doSearch/value: string/ {
console.log/`value=${value}`/;
this.router.navigateByUrl/`/search/${value}`/;
}
}


线 "value" 对应于定义的路由 app.module.ts:


const routes: Routes = [
// other routes
{path: 'search/:keyword', component: ProductListComponent},
];


然后组件使用查询处理服务。
</input>

要回复问题请先登录注册