0
I have the following service, however, it is not accepting that I set it to null start pro Subject, keeps returning the error: Argument of type 'null' is not assignable to parameter of type 'Comodo[]'.
This is my service:
private comodoSubject$: BehaviorSubject<Comodo[]> = new BehaviorSubject<Comodo[]>(null);
private loaded: boolean = false;
constructor(private http: HttpClient) { }
getComodos(): Observable<Comodo[]>{
if(!this.loaded){
this.http.get<Comodo[]>(`${this.url}/comodos`)
.pipe( tap((coms) => console.log(coms)))
.subscribe(this.comodoSubject$);
this.loaded = true;
}
return this.comodoSubject$.asObservable();
}
addComodos(d: Comodo): Observable<Comodo>{
return this.http.post<Comodo>(`${this.url}/comodos`, d)
.pipe(
tap((com: Comodo) => this.comodoSubject$.getValue().push(com))
)
}
My interface is stated as follows:
export interface Comodo {
name : string;
_id ?: string;
}
I don’t know what to do to allow him to use Comodo[] in this format.
That’s right, thank you!
– Geraldão de Rívia