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

458
Views
Selección iónica: el valor preseleccionado es invisible hasta que se hace clic una vez

Acabo de crear una selección de iones en la versión iónica 6. Mi problema es que preseleccioné con éxito un valor cuando se carga la página, pero este valor de preselección no se muestra en la interfaz de usuario.

Simplemente aparece después de haber hecho clic en seleccionar, pero antes no aparece (como puede ver en la imagen 2). ¡Cargué los datos en el método ionViewWillEnter y los preseleccioné con un NgModel!

Puedes verlo aqui:

Se ve así cuando se cargó la página

Se ve así cuando abro la selección (el valor de preselección fue exitoso

Código HTML para la selección

 <ion-row> <ion-col> <ion-item lines="inset"> <ion-label hidden>Abteilungen wählen</ion-label> <ion-select (ionChange)="loadOpenTicketsForDepts()" style="min-width: 100%" placeholder="Abteilungen wählen..." multiple [(ngModel)]="selectedDepartments" cancelText="Abbruch" okText="OK"> <ion-select-option value="{{dept.id}}" *ngFor="let dept of departments"> {{dept.name}} </ion-select-option> </ion-select> </ion-item> </ion-col> </ion-row>

Carga de datos mecanografiados:

 ionViewWillEnter(): void { //1. get department where logged in emp is working in this.authService.getPersNr().then((res) => { //now load dept this.ticketService.getEmployeeByName(res).subscribe(emp => { const costcenter = emp.costcentreId; this.costCentreService.getDepartmentById(costcenter).subscribe(dept => { //add to selected departments if it is not already in if (this.selectedDepartments.includes(String(dept.id)) == false) { this.selectedDepartments.push(String(dept.id)) } //now load tickets for all selected departments this.loadOpenTicketsForDepts(); }) }) }) this.costCentreService.getDepartments().subscribe(res => { this.departments = res; })

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agregue una referencia a su selector llamado #departmentSelector:

 <ion-select #departmentSelector (ionChange)="loadOpenTicketsForDepts()" style="min-width: 100%" placeholder="Abteilungen wählen..." multiple [(ngModel)]="selectedDepartments" cancelText="Abbruch" okText="OK"> <ion-select-option value="{{dept.id}}" *ngFor="let dept of departments"> {{dept.name}} </ion-select-option> </ion-select>

Luego, puede acceder a él desde su clase de mecanografiado después de ver Cargado:

Declara tu referencia:

 @ViewChild("departmentSelector") departmentSelector!: IonSelect;

Entonces podría acceder a él cuando la vista esté completamente cargada:

 ngAfterViewInit(){ //your async function ... this.authService.getPersNr().then((res) => { //now load dept this.ticketService.getEmployeeByName(res).subscribe(emp => { const costcenter = emp.costcentreId; this.costCentreService.getDepartmentById(costcenter).subscribe(dept => { //add to selected departments if it is not already in if (this.selectedDepartments.includes(String(dept.id)) == false) { // this.selectedDepartments.push(String(dept.id)) this.departmentSelector.value = String(dept.id); } //now load tickets for all selected departments this.loadOpenTicketsForDepts(); }) }) }) // }
about 4 years ago · Juan Pablo Isaza 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!