Hello. I am trying to sample data (for example, to get records in which the number is equal to something. Without filter, everything works)

http.get(baseUrl + 'api/Student/Students1') .filter( stud => stud.Phone == 123) .subscribe(data => { this.studentTEST = data.json() as Students[]; }, error => console.error(error)); 

Mistake:

"Property 'Phone' does not exist on type 'Response'".

The angular version was 4.2.5, then changed in package.json to 5.1.0 and, like npm, updated to version 5.

How else can you filter the data?

It seems to understand. (For example, sample data (weather) from the template vs angular works). But my data from the database does not filter

Controller:

 [HttpGet] public IEnumerable<Students> GetStudent() { return db.Students; } 

Interface Students:

 interface Students { Address: string; Email: string; Phone: string; StdName: string; } 

Request:

 http.get(baseUrl + 'api/Student/Students1') .subscribe(result => { this.std = (result as Students[]).filter(s => s.Email === "ffff"); }, error => console.error(error)); 

If you do filter(std => std.Email != "ffff") , for example, it displays everything, but if you try to filter something, it doesn't output anything

    1 answer 1

    Hello! You apply filter to the stream, not the data.

      http.get(baseUrl + 'api/Student/Students1') .map( data => data.json().filter(s => s.Phone === 123)) .subscribe(data => { this.studentTEST = data as Students[]; }, error => console.error(error)); 

    I hope this solution will suit you.

    • Thanks for the answer. Error "Parameter 's' implicitly has an 'any' type." - St.S
    • You need to specify the type for the variable s . - Tori X
    • There are no errors now, but it does not display any data .... - St.S
    • Can somehow filter out differently? - St.S
    • Tell me, did you use the advice that you were given in the English-speaking community? In the sample code, I saw that you commented out subscribe , please do not forget to uncomment it before testing. Because otherwise the Observable will not work. I hope you will also render this method to the service. I tried to reproduce the error, but it didn’t work out for me :( We’ll out until the end.) - Tori X