1

I am trying to make multiple API request to an endpoint in which the values are iterated over an array

So I used rxjs forkJoin to achieve this

//array to keep obeserbles
propOb: Observable<any>[];

input.property.forEach(property => {
         console.log('prop', property);
         const t = this.baseApiService.sendRequest(
          'json',
          {
           method: 'post',
           endPoint: 'v1/property/new',
           data: {
              property_id: uuid.v4(),
              ics_ref_no: '122',
              property_type: property.type,
              property_role: property.role,
              property_dec: property.description,
              
           }
         });
         this.propOb.push(t);
         });

    forkJoin(this.propOb).subscribe((data) => {
           console.log(data);
    });

While running i am getting the following error cannot read property 'push' of undefined from this line this.propOb.push(t);

Also, I'm not sure my approach is correct or not

1 Answer 1

3

You need to initialize the array. It's has 'undefined' type until you do so.

change

propOb: Observable<any>[];

to

propOb: Observable<any>[] = [];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.