1

aca les dejo mi codigo

Este es mi models

export interface Respuesta {
    num_reclamo: number;
    rut_admin: number;
    texto_respuesta: string;
    fecha_respuesta: string;
    SLA_respuesta: string;
}

Este es mi respuesta service

    import { Injectable } from '@angular/core';
    import { HttpClient, HttpHeaders } from '@angular/common/http';
    @Injectable({
        providedIn: 'root'
    })
    export class RespuestaService {

       private URL = 'localhost:8080/api'
       httpOptions = {
        headers: new HttpHeaders({ 'Content-Type': 'application/json' })
       };

      constructor(private http: HttpClient) { }

      responderReclamo(num_reclamo: number) {
          const suffix = '/ADMIN/pendientes/respuesta'
          return this.http.post(this.URL+suffix+num_reclamo, this.httpOptions);
        }
    }

Y este es mi componente.ts que es donde me marca el error

      import { Component, OnInit, Input } from '@angular/core';
      import { Respuesta } from 'src/models/Respuesta';
      import { RespuestaService } from 'src/app/services/respuesta-service.service';
      import { ActivatedRoute } from '@angular/router';
      import { Location } from '@angular/common';
      @Component({
         selector: 'app-respuesta-de-reclamo',
         templateUrl: './respuesta-de-reclamo.component.html',
         styleUrls: ['./respuesta-de-reclamo.component.css']
      })
      export class RespuestaDeReclamoComponent implements OnInit {

          @Input() respuesta: Respuesta;

          constructor(
            private respuestaService:RespuestaService,
            private ruta: ActivatedRoute,
            private ubicacion: Location
          ) {}

          ngOnInit(): void {}

          volver(){
             this.ubicacion.back();
          }

          guardar(num_reclamo:number, rut_admin:number, 
                  texto_respuesta:string, fecha_respuesta:string, 
                  SLA_respuesta: string){
              this.respuestaService
                  .responderReclamo({num_reclamo, 
                         rut_admin, texto_respuesta, fecha_respuesta, 
                         SLA_respuesta} as Respuesta)
                  .subscribe(_=>this.volver());
           }
      }

El error que me marca, al situarme encima de

(property) Respuesta.texto_respuesta: string Argument of type 'Respuesta' is not assignable to parameter of type 'number'.ts(2345

Agradezco sus respuestas!!

2
  • Hola. No entiendo donde te da el error.
    – Legna
    el 9 may. 2020 a las 22:11
  • Al situarme en la linea ({num_reclamo, rut_admin, texto_respuesta, fecha_respuesta, SLA_respuesta} as Respuesta), disculpa no me dejo subir mas codigo para señalar bien el 9 may. 2020 a las 22:14

1 respuesta 1

3

La funcion responderReclamo(num_reclamo: number) recibe un parametro de tipo number y se llama num_reclamo. Si lo que quieres es recibir:

{num_reclamo, rut_admin, texto_respuesta, fecha_respuesta, SLA_respuesta} as Respuesta

Entonces modifica de esta manera:

responderReclamo(respuesta: Respuesta)

Y ya en tu servicio mandas :

const suffix = '/ADMIN/pendientes/respuesta'
    return this.http.post(this.URL+suffix+ this.respuesta.num_reclamo, this.httpOptions);
9
  • No me funciona, me marca error en responderReclamo esto.. : Expected 1 arguments, but got 2.ts(2554) 'Respuesta' only refers to a type, but is being used as a value here.ts(2693) y tambien Cannot find name 'respuesta'. Did you mean the instance member 'this.respuesta'?ts(2663) y en el service me lanza Cannot find name 'respuesta'.ts(2304) el 9 may. 2020 a las 22:34
  • 1
    Error mio. Cannot find name 'respuesta'. te da el error por que no puse el this.respuesta
    – Legna
    el 9 may. 2020 a las 22:43
  • Me pide declararla, la coloco como respuesta: any; o respuesta: Respuesta en el service el 9 may. 2020 a las 22:45
  • 1
    Checa mi pregunta. Edite el último bloque de comentario para que no te de el error.
    – Legna
    el 9 may. 2020 a las 22:46
  • Ya no me marco error, lo voy a probar el 9 may. 2020 a las 22:48

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.