Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Ionic angular modal, bug function execute before console.log

I have two page as modal, the first calling the second first page .ts

export class FirstPage implements OnInit {
    filter: any = {
        date: {
            begin: null,
            end: null
        },
        lieu: [],
        price: {
            min: null,
            max: null,
            monnaie: null
        },
        hobbies: [],
        participants: {
            min: null,
            max: null
        },
        distance: {
            min: null,
            max: null
        }
    }

    constructor(
        private modalController: ModalController,
    ) { }

    ngOnInit() {

    }

    goBack() {
        this.nav.back();
    }

    searchEvent(){
        console.log('search', this.filter)
        let filtreTmp = this.filterBeforeSearch(this.filter)

        console.log('this filter after before filter', filtreTmp, this.filter)
    }

    filterBeforeSearch(filter){
        console.log('traitement search', filter)
        var filtreTmp = { ...filter }
        console.log('tmp', filtreTmp, filter)

        filtreTmp.hobbies = filtreTmp.hobbies.map(item => item.id)
        filtreTmp.lieu = filtreTmp.lieu.map(item => item.id)

        if(filtreTmp.price.monnaie){
            console.log('traitement')
            filtreTmp.price.monnaie = filtreTmp.price.monnaie.id
        }

        console.log('this filter', filtreTmp, filter)

        return filtreTmp
    }

    async showFilters() {
        const popover = await this.modalController.create({
            component: SecondPage,
            cssClass: 'modal_specific_pays',
            swipeToClose: true,
            presentingElement: await this.modalController.getTop(),
            componentProps: {
                filter: JSON.stringify(this.filter)
            }
        });

        popover.onDidDismiss().then((dataReturned) => {
            if(dataReturned.data){
                this.filter = dataReturned.data;
                console.log('data returned', this.filter)
                this.searchEvent()
            }
        });

        return await popover.present();
    
    }
}

my logic is when the modal is onDidDismiss, i set the data returned to the filter of first page; in my searchEvent my filter.price.monnaie has object as value on dismiss modal, and with function filterBeforeSearch i change this object into string of id;

so when i comment the this.searchEvent inside my onDidDismiss the monnaie type sill object, and when i uncomment it, all console.log above the treatment that change this object into string show that the value of monnaie already changed into string as if the treatment is executed before the console.log. So i don't know where in this code this value was changed before the treatment is executed cause if i comment the treatment, the value type is an object;

second problem: i've used { ...this.filter } and Object.assign({}, this.filter) to clone this.filter value into filterTemp to avoid that my this.filter value is change by the treatment but it always changed.

PS: i use node v14.17 if it related to node

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda