Type 'Observable<Arraybuffer>' is not Assignable to type 'Observable<Entity>'

Asked

Viewed 431 times

0

I was doing an Angular 10 + Spring boot course and came across the following mistakes:

Type 'Observable' is not Assignable to type 'Observable'. Type 'Arraybuffer' is Missing the following properties from type 'Entity': id, Description, done, createdDate, doneDate. Argument of type 'String' is not Assignable to Parameter of type 'string'. 'string' is a Primitive, but 'String' is a wrapper Object. Prefer using 'string' when possible.

This error occurs in the class corpo.service.ts. Classes below:

body.service.ts

import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { Entidade } from './entidade'

import { HttpClient } from '@angular/common/http'

@Injectable({
  providedIn: 'root'
})
export class CorpoService {

    apiURL: String = 'http://localhost:8080/api/entidades';

  constructor(
   private http: HttpClient 
  ) { }

  salvar (Entidade: Entidade) : Observable<Entidade>{
  return  this.http.post<Entidade>(this.apiURL, entidade)
}
}

entity ts.

export class Entidade {
    id: number;
    description: string;
    done: boolean;
    createdDate: string;
    doneDate: string;
}

app.componentts.

import { Entidade } from './entidade';
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms'
import { CorpoService } from './corpo.service'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  form: FormGroup = new FormGroup({
    description : new FormControl('')
  })

  constructor (
    private service: CorpoService
  ){}

  submit(){
    console.log(this.form.value)
    const entidade: Entidade = { ...this.form.value}
    this.service
    .salvar(entidade)
    .subscribe(savedEntidade => console.log(entidade) )
  }
}

Could someone help me?

  • What would be entity in this passage: return this.http.post<Entidade>(this.apiURL, entidade)?

  • In case it would be he would be saving the attributes of the entity class.ts

1 answer

0

People already found the error, in case the error was in apiURL: String = 'http://localhost:8080/api/entities'; I changed the string to string and it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.