I have this Interface to shape my API Response -
interface MyTest {
property2: string
}
This is my Angular 5 Service Code -
getAPI(searchKey: string) {
this.productsAPIUrl =
https://localhost:44331/api/SampleData/WeatherForecasts2";
return this.http.get<MyTest>(this.productsAPIUrl);
}
My Actual API Response - https://localhost:44331/api/SampleData/WeatherForecasts2 is
{"property1":"Property1","property2":"Property2","property3":"Property3"}
Now I am calling this Angular Service in my Component like below -
public incrementCounter() {
this.getAutocompleteSuggestions().subscribe((data: MyTest) => {
console.log(data);
});
}
So Here my Question is After calling Angular Service, I am getting Entire Response. But Here I cast my API response as Type 'MyTest' which has only property2 but still WHY AM I GETTING ENTIRE RESPONSE?
HOW DO I CAST MY API Response in subset? How to Extract API Response and how to MAP it to my custom model type MyTest????
I need only Property2. So How can i map it???
this.getAutocompleteSuggestions().pipe(map(data => data.property2)).subscribe((data: MyTest)this.getAutocompleteSuggestions().pipe(map(data => { return { property2: data.property2}})).subscribe((data: MyTest)?