Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
ionViewWillEnter no dispara (ionic 2, angular 2, typescript)

Paso los datos correctos a this.items, pero no aparece después de cambiar a la vista, cuando el método ionViewWillEnter generalmente debería activarse. En cambio, lo hace después de escribir algo en mi barra de búsqueda.

Método ionViewWillEnter:

 ionViewWillEnter() { ... this.http.post('http://www.example.com/select.php', creds, { headers: headers }) .map(res => res.json().User) .subscribe( data => this.data = data.map(user => user.Name), err => this.logError(err), () => console.log('Completed') ); this.items = this.data; }

barra de búsqueda:

 getItems(ev) { // Reset items back to all of the items this.initializeItems(); // same code as ionViewWillEnter // set val to the value of the ev target var val = ev.target.value; // if the value is an empty string don't filter the items if (val && val.trim() != '') { this.items = this.items.filter((item) => { return (item.toLowerCase().indexOf(val.toLowerCase()) > -1); }) } }

mi html:

 <ion-searchbar (ionInput)="getItems($event)"> </ion-searchbar> <ion-list> <ion-item *ngFor="let item of items"> {{ item }} ...
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tenga en cuenta que las solicitudes Http (las que está utilizando en su función ionViewWillEnter() ) son asíncronas. Esto significa que cualquier código fuera del alcance de la solicitud continuará ejecutándose mientras su aplicación realiza una solicitud al servidor.

Realiza la asignación de this.data a this.items al final del evento del ciclo de vida, pero lo hace fuera de su solicitud Http. Realice la asignación dentro de los data => devolución de llamada, en su lugar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!