Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda