angular - 我的过滤器不能在有角度的垫子上工作
问题描述
我的过滤器不能以角度工作,我的ts
文件代码是:
private _jsonURL = 'assets/mytestusers.json';
ngOnInit() {
this.http.get(this._jsonURL).subscribe((data) => this.displaydata(data));
// this.formdata1 = new FormGroup({srchval: new FormControl()});
this.formSubscribe();
this.getFormsValue();
}
displaydata(data: Object) {
this.httpdata = data;
}
displayedColumns: string[] = ['position', 'name', 'username', 'email', 'address', 'action'];
// none value
filterValues = {
name: ''
};
// form group
filterForm = new FormGroup({
name: new FormControl()
});
get name() {
return this.filterForm.get('name');
}
formSubscribe() {
if (this.name != null) {
this.name.valueChanges.subscribe(nameValue => {
this.filterValues['name'] = nameValue;
this.httpdata.filter = JSON.stringify(this.filterValues);
});
}
}
// create filter
getFormsValue() {
this.httpdata.filterPredicate = (data: any, filter: string): boolean => {
let searchString = JSON.parse(filter);
const resultValue =
data.name.toString().trim().toLowerCase()
.indexOf(searchString.name.toLowerCase()) !== -1;
return resultValue;
};
this.httpdata.filter = JSON.stringify(this.filterValues);
}
和 html 文件是
<form [formGroup]="filterForm">
<div>
<div class="form-group">
</div>
<div>
<label for="">Name</label>
<mat-form-field>
<input matInput formControlName="name" placeholder="Enter name">
</mat-form-field>
</div>
</div>
</form>
我的json
文件是
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna@melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
}
]
解决方案
推荐阅读
- html - 改变
- sql - SELECT VARIABLE - 动态命令
- asp.net - 如何将时间条目合并到单行中以用于每周报告?
- python - 保存时如何忽略我的表单集的未更改表单?
- python - 将许多变量传递给 Jinja render_template() 时的风格好吗?
- r - Reshape2:dcast() 返回 - 'sum' 对因子没有意义
- elasticsearch - Elasticsearch - 将视频目录信息建模为一个索引与多个索引
- javascript - FontAwesome 图标未显示按钮
- java - 最终提交请求后,我在成功页面中得到空响应
- python - Kubernetes Python 客户端 - 一次查找待处理作业并安排所有 pod 或如何安排待处理作业