How to take or manipulate data inside subscribe - Angular

Asked

Viewed 980 times

1

Unfortunately I can’t, even inside the subscribe, scroll through the variable fixtures$ I can send the data to html and show in the table. However I need to manipulate the data to save in the bank already in its own ". Component".

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

 for (var i = 0; i < this.fixtures$.length; i++) {
            this.fixtures$[i].name = this.fixture$[i].id +' '+ this.fixtures[i].name 
            } 

It didn’t work either.

After several and several attempts, I was able to make it work with the code below; /service/

    getFixtures(): Observable<any> {
      return this._http.get(this.baseUrl)
     .pipe(map(response => response));
  }

Component.

ngOnInit() {
this.simpleBet.getFixtures().subscribe(
  data => {
    this.fixtures$ = data.data;
    this.fixtures$.forEach(x =>

       console.log(this.fixtures$, x)

       )
       for (var i = 0; i < this.fixtures$.length; i++) {
       console.log( this.fixtures$[i].name = this.fixtures$[i].id +' '+ this.fixtures$[i].name[i]) 
        } 
  },
  error => {
    this.errorMessage = `${error.status}: ${JSON.parse(error.error).message}`;
  }
);

}

  • Take a look at the network tab that it is returning your backend data correctly. and puts the code instead of image https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions

  • So, as I said, I can send there, but for example I would like to take the data of Fixture$ do a go and save this data in the database however, if I put a console. log for example in the variable fixtures$ it is as Undefined, on the image is pq I already had them and the view of the code is perfect, so the photos.

  • you are getting an endpoint get a look that this endpoint is returning the correct data. Give a look at the link I sent you should not use images instead of code.

  • Yes, I know I’m getting the endpoint data, but since I’m still inexperienced in Angular I can’t manipulate him or know the correct way to do it, I was told that I can’t because he’s asymptomatic and I have to perform the go inside the subcribe, I tried several ways looking at other posts, but did not understand what I am doing wrong. please give me a north I’ll be grateful msm.

  • It would be easier to assist you if you had placed the code instead of putting code prints. The problem seems to be in service, remove the pipe from there, and modify the function return getFixtures for Observable<Fixture[]> to test, place a console.log date inside the subscribe of the function calling the getFixtures, post here the results.

  • I still don’t believe it would help much more in this case, being that you can view it the same way or better, but on the issue I really appreciate the tips, but instead returned another object. vlw.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.