Eu estava fazendo um curso de Angular 10 + Spring boot e me deparei com o seguintes erros:
Type 'Observable' is not assignable to type 'Observable'. Type 'ArrayBuffer' is missing the following properties from type 'Entidade': 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.
Esse erro ocorre na classe corpo.service.ts
.
Classes abaixo:
corpo.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)
}
}
entidade.ts
export class Entidade {
id: number;
description: string;
done: boolean;
createdDate: string;
doneDate: string;
}
app.component.ts
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) )
}
}
Alguém poderia me ajudar?
return this.http.post<Entidade>(this.apiURL, entidade)
?