• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

173
Vistas
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 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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 3 years ago · Juan Pablo Isaza Denunciar
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda