我尝试过滤数据(获取给定数字的记录)
http.get(baseUrl + 'api/Student/Students1')
.filter( stud => stud.Phone == 123)
.subscribe(data => {
this.studentTEST = data.json() as Students[];
}, error => console.error(error));
但得到错误:
““响应”类型上不存在属性“电话””。
Angular 的版本是 4.2.5,但最近在 package.json (5.1.0) 中进行了更新。寻找
我从 asp.net 核心控制器获取数据库上下文。
这是我的角度代码:
import { Component, Inject } from '@angular/core';
import 'rxjs/Rx';
import { Http, Response } from '@angular/http';
import { Observable } from 'RxJS';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
@Component({
selector: 'fetchdata',
templateUrl: './fetchdata.component.html'
})
export class FetchDataComponent {
public studentTEST: Students[];
public stud: Students[];
constructor(private http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl + 'api/Student/Students1')
.map((response: Response) => response.json() as Students[])
.filter(stud => stud.Phone === 123);
//subscribe(result => {
//this.studentTEST = result.json();
}
}
export interface Students {
StdName: string;
Email: string;
Phone: number;
Address: string;
}
现在错误:
类型“学生 []”上不存在属性“电话”。