I’m trying to map and filter a JSON inside a component but I have not succeeded, from the service “data.services.ts” I had no problem, but when taking the data to the component “tab1.page.ts” I couldn’t, the usual thing I do is use:
.pipe(
map((res: any) => {
return res
})
);
Tab1.page.ts
import { Component, OnInit } from '@angular/core';
import { DataService } from '../services/data.services';
import { map } from "rxjs/operators";
import { filter } from "rxjs/operators";
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page implements OnInit {
items = []
constructor(private dataService: DataService) {}
ngOnInit(): void {
this.dataService.getRemoteData().subscribe(date=> {
this.items = date
})
}
}
data.services.ts
import { Injectable, Input } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { map } from "rxjs/operators";
import { filter } from "rxjs/operators";
@Injectable({
providedIn: "root"
})
export class DataService {
constructor(private http: HttpClient) {}
getRemoteData() {
return this.http
.get("https://api")
.pipe(
map((res: any) => {
return res.prosugApi
})
);
}
}