I have an event class, and a method that is called snapdbEvent (), but when I put the object in it and try to define the values of the variables in the object, the following error occurs:
PrintfromDB
I have an event class, and a method that is called snapdbEvent (), but when I put the object in it and try to define the values of the variables in the object, the following error occurs:
PrintfromDB
When assigning the values in the class it is recommended to use setters functions or a constructor, for example:
class export Evento {
id: string;
horaInicio: string;
horaFim: string;
constructor(values: Object) {
Object.assign(this, values);
// Ou
this.id = values.id;
this.horaInicio = values.horaInicio;
this.horaFim = values.horaFim;
}
setHoraInicio(horaInicio) {
this.horaInicio = horaInicio;
}
setHoraFim(horaFim) {
this.horaFim = horaFim;
}
}
and its attribution method in the component or provider:
private evento:Evento
chamaAPI() {
apiService.getEventos().subscribe(res => {
this.evento = new Evento(res.evento);
});
}