0
First of all, excuse my Portuguese, I don’t write it well and I’m using a translator, but I can read it well enough.
I have a problem connecting an observable that I create in a service with a variable of a component. Here is the code:
servicio1.ts
private myObservable$ = new Subject<myInterface>();
constructor() {
this.crearObservable$();
}
nuevoObjeto(dato1: string, dato2: string): myInterface {
return {
datoUno: dato1,
datoDos: dato2,
};
}
crearObservable$() {
let observableAUX: myInterface;
observableAUX = this.nuevoUsuario("Dato 1", "Dato 2");
this.myObservable$.next(observableAUX);
}
getObservable$(): Observable<myInterface> {
return this.myObservable$.asObservable();
}
Component1.ts
datos: Observable<myInterface>;
datos: Usuario;
ngOnInit(): void {
this.datos$ = this.servicio1.getObservable$();
this.datos$.subscribe(datos => this.datos = datos);
console.log(this.datos);
}
Of course both the service and the interface are not imported anywhere.
But for some reason `these.data' do not receive the values.
I’d appreciate your help.
Thank you in advance.