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

220
Views
Cómo mostrar datos del servicio al cliente en ngx-wheel Angular

Quiero mostrar la rueda ngx usando api pero tengo problemas para mostrar los datos. Aquí mi servicio:

 import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class RestServices { restEndpoint:string = 'https://gorest.co.in/public/v2/users' constructor( private httpClient: HttpClient ) { } async getServiceId() { const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', }) } return this.httpClient.get<any[]>(this.restEndpoint, httpOptions) }

Aquí mi componente:

 private subscription: Subscription | undefined; items: any = [] ngOnInit(): void { this.subscription = this._restService.getServices() .subscribe((res:any)=>{ let item = res this.items = item.map((v:any) => ({ text: v.name, id: v.id, textFillStyle: "white", textFontSize: "16" })); }) } ngOnDestroy(): void { this.subscription?.unsubscribe() }

Aquí para html

 <ngx-wheel #wheel [width]='350' [height]='350' [spinDuration]='8' [disableSpinOnClick]='true' [items]='items' [innerRadius]='10' [spinAmount]='10' [textOrientation]='textOrientation' [textAlignment]='textAlignment' pointerStrokeColor='black' pointerFillColor='white' [idToLandOn]='idToLandOn' (onSpinStart)='before()' (onSpinComplete)='after()'>

Espero encontrar la respuesta aquí. Gracias

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

0

Primero, no necesita await, async y ,toPromise()... elimínelos y simplemente regrese

 return this.httpClient.get<any[]>(this.restEndpoint, httpOptions);

dentro de su componente, debe usar su constructor solo para la inicialización de datos simple: si tiene que consumir una API de descanso, es un mejor enfoque mover esa pieza de código dentro del método ngOnInit:

 items: any[] = [] constructor(private restService: RestService){}//dependency injection ngOnInit(): void { this.restService.getServiceId().subscribe(response => { console.log('response success: ', response); this.items = response; //this may change a little based on your api console.log('items: ', this.items); }, errorLog => { console.log('response error: ', errorLog) }); }

La solución anterior es válida, puede enriquecerla agregando *ngIf="isLoaded" en su elemento html y establecer en verdadero el método de suscripción isLoaded INSIDE. pero si lo prefieres puedes hacer lo siguiente en el component.ts

 items$: Observable<any> = EMPTY; constructor(private restService: RestService){}//dependency injection ngOnInit(): void { this.items$ = this.restService.getServiceId(); }

entonces, en tu html cambiaría a lo siguiente:

 <ngx-wheel #wheel *ngIf="items$ | async as items" [width]='350' [height]='350' [spinDuration]='8' [disableSpinOnClick]='true' [items]='items' [innerRadius]='10' [spinAmount]='10' [textOrientation]='textOrientation' [textAlignment]='textAlignment' pointerStrokeColor='black' pointerFillColor='white' [idToLandOn]='idToLandOn' (onSpinStart)='before()' (onSpinComplete)='after()'>
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!