My map function in this code block:
public async getAllWidgets2(): Promise<Widget[]> {
let url = "myUrl";
var items = [];
return axios.get(url).then(result => {
console.log("results" + result)
let result2: Widget[] = [];
result.map((item) => { result2.push(this.parseWidget(item)); });
let data: Widget[] = result2;
return(data);
} ) }
The map functions above gives me an error "Property 'map' does not exist on type 'AxiosResponse'.ts(2339)"
I searched on answers on StackOverflow and tried:
import { map } from 'rxjs/operators';
But still gives me the same error. Any way to solve it?
My map function in this code block:
public async getAllWidgets2(): Promise<Widget[]> {
let url = "myUrl";
var items = [];
return axios.get(url).then(result => {
console.log("results" + result)
let result2: Widget[] = [];
result.map((item) => { result2.push(this.parseWidget(item)); });
let data: Widget[] = result2;
return(data);
} ) }
The map functions above gives me an error "Property 'map' does not exist on type 'AxiosResponse'.ts(2339)"
I searched on answers on StackOverflow and tried:
import { map } from 'rxjs/operators';
But still gives me the same error. Any way to solve it?
Share Improve this question asked Jun 18, 2020 at 13:57 ArteArte 4172 gold badges6 silver badges16 bronze badges 1 |1 Answer
Reset to default 24Axios Response does not only contain the response body, it is an object containing all the details about the request, the response, etc...
If you want to map the response body (data), you have to do all of this on 'response.data' and not 'response' :)
type
of result?.map()
is a method on Arrays. It doesn't look like you are using rxjs, so I don't think the rxjs/operators import is needed. – joshvito Commented Jun 18, 2020 at 14:01