I'm trying to implement this but need some help (I'm new to this).
I currently have,
constructor(http: HttpClient, private cvservice: CvService) {
const req = http.post<any>('url', [{
"name": "ids",
"license": "GPL version 2"
}])
.subscribe(
res => {
console.log(res);
var resp = res.Results[0].results.map(x => {
return {cvid: x.ID, severity: x.CVSS };
} );
this.data = [...resp];
},
err => {
console.log("Error occured");
}
);
}
This works fine except I need to make the http.post synch (need Results[0] before continuing) and I'm using the suggestion from, How to synchronise Angular2 http get?.
I've modified the service as,
export class CvService {
constructor(private http: HttpClient) {
}
url = 'foo';
getIds():Observable<any[]> {
const url='xxx';
return this.http.post(url, [{
"name": "ids",
"license": "GNU General Public License GPL version 2"
}])
.map(
res => {
res.Results[0].results.map( x => {
return {cvd: x.ID, severity: x.CVSS };
}));
}
}
}
But I think this syntax is wrong. This gives compile error. Can someone please clarify the correct way to use the map function here?