how to replace a push with a splice

Viewed 41

**

UPDATE

I already know my mistake but now I need help on how to add a splice, in each function I have a push that adds the data in x position, my question is, how can I change that push for a splice and tell it what position I want it to take that data by that the promise.all when it is executed is random and I could not know the position that is why it gave me an error at the beginning, in this part I use the push, I must change them to splice:

       this.opcionServicio = response;
       this.opcionesServicio.push(this.opcionServicio);
       this.servicio.push(this.opcionesServicio[0].ticket_field.title)
       customFieldOption.id = this.opcionServicio.ticket_field.id;
       customFieldOption.name = this.opcionServicio.ticket_field.title;
       this.customFieldOptions.push(customFieldOption);

**

I have a question, does anyone know why my code doesn't work? I have 4 functions, each function is a promise and in the ngOnInit it loads these functions, I put them with a Promise.all, in the console it prints the array but when I enter the screen the "loading" does not appear and it does not appear the information I want...

processing is a "loading" type I only put 2 functions but the other 2 have almost the same

ngOnInit(): void {
Promise.all([this.getData1, this.getData2]).then(values => {
            console.log(values)
            this.processing = true;
          }).catch(reason => {
            console.log('error get data',reason)
          });
}




 public getData1() {
        return new Promise((resolve, reject) => {
            this.createService.getServiceData1().subscribe(
                (response: any) => {
                    let customFieldOption: CustomFieldOption = new CustomFieldOption();
                    this.opcionServicio = response;
                    this.opcionesServicio.push(this.opcionServicio);
                    this.servicio.push(this.opcionesServicio[0].ticket_field.title)
                    customFieldOption.id = this.opcionServicio.ticket_field.id;
                    customFieldOption.name = this.opcionServicio.ticket_field.title;
                    this.customFieldOptions.push(customFieldOption);
                    resolve(true);
                },
                (error) => {
                    console.log(error);
                    reject(true);
                }
            );
        });
    }




 public getData2() {
            return new Promise((resolve, reject) => {
                this.createService.getServiceData2().subscribe(
                    (response: any) => {
                        let customFieldOption: CustomFieldOption = new CustomFieldOption();
                        this.opcionServicio = response;
                        this.opcionesServicio.push(this.opcionServicio);
                        this.servicio.push(this.opcionesServicio[0].ticket_field.title)
                        customFieldOption.id = this.opcionServicio.ticket_field.id;
                        customFieldOption.name = this.opcionServicio.ticket_field.title;
                        this.customFieldOptions.push(customFieldOption);
                        resolve(true);
                    },
                    (error) => {
                        console.log(error);
                        reject(true);
                    }
                );
            });
        }
0 Answers
Related