Error while iterating an http-client return

Hello friends,
I am trying to create a table with the data returned by the server, however I am getting the following message.

Value for ‘myvariavel’ is non-repeatable.

My http-client method is like this.

import { inject } from 'aurelia-framework';
import { HttpClient } from 'aurelia-http-client';

@inject(HttpClient)
export class ServicoProvider{
  constructor(http) {
    this.collection = [];
    this.entity = null;

    this.http = http;
    this.http.configure(x => {
      x.withBaseUrl('http://localhost:8000');
    });
  }

  get() {
    return this.http.get('/servicos')
      .then(data => { return data.content; })
      .catch(error => {
        console.log('Deu muita merda...');
        // console.log(error);
      });
  }
}

Try this:

return this.http.get("servicios"). 
       then(response => response.json()).
       then(data => data.content)

You need to turn the response to JSON

1 Like

Hi,
I made the change, but the return now is Json is not a function.

What @AlbertoDePena mentioned would be applicable for the fetch client which you are not using. The error sounds different though. Can you show the custom element consuming the Provider? myvariavel sounds like the prop you are assigning the Ajax result of get to. Likely youre not awaiting the result, thus repeating over a promise which of course is not repeatable.