0

I am using httpClient to make an http call to an api and display the items in an ngfor. It seems to work cause I have three items being displayed in my list just as the three items being return from my api. However I can't seem to access the return json data. When I look at network call in the network tab in chrome I see a 200 success, but the response is html. I am guessing I need to specify the json data type somewhere, but I'm not sure.

Here is my http call in my service:

  getProducts(): Observable<Product[]> {
    return this.http.get<Product[]>(this.competitionUrl)

Here is how I am trying to consume the data in my component:

productlist = this.productdataservice.getProducts()

In my html:

<ion-list *ngFor="let product of productlist | async; let i = index">
  <button ion-item>
    <ion-avatar item-start>
      <img src="../../assets/icon/favicon.png">
    </ion-avatar>
    <h2>{{product.productName}}</h2>
  </button>
</ion-list>

My list displays three icons as it should because my api returns three products, but when I look at the network call from my angular front end page, I don't see the json data.

Piyush Jain
  • 1,895
  • 3
  • 19
  • 40
mo_maat
  • 2,110
  • 12
  • 44
  • 72
  • @mo-maat check in postman or any rest-client make sure you're receiving json response. – Rajesh Jun 15 '20 at 03:12
  • I just checked using postman and I am getting a json response. – mo_maat Jun 15 '20 at 03:22
  • Are you sure? Can you copy the response json and paste into [json parser] (http://json.parser.online.fr/beta/) check json is valid – Rajesh Jun 15 '20 at 03:28
  • Actually so going to back to my api, it does seem like I am not returning json type data even thought it is formatted that way in the site you suggested and on postman. I'm checking how to explicitly specify that on my api. – mo_maat Jun 15 '20 at 03:50
  • First check in your API endpoint . may be its not properly set for return JSON format – CodeMind Jun 15 '20 at 04:17
  • Ya. I've checked everything. I've even explicitly set the attribute `[Produces("application/json")]` but no luck. I'm using .net core 2.2. I also tried this `options.Filters.Add(new ProducesAttribute("application/json"));` per docs but filters is not a property. – mo_maat Jun 15 '20 at 04:29
  • I resolved my issue. I was looking at the response instead of the preview tab of chrome's network tab so I thought it was showing a string instead of json. It is actually returning json as I want it to so I'm all set. – mo_maat Jun 15 '20 at 04:48

0 Answers0