I cant assign value to any var from the return of the subscribe, my observable name is reportess and I trying to assign the value to var in the same service that I declared the observable from external component. In the other hand I can print by log the return of the subscribe.
Service:
import { Injectable, Input } from '@angular/core';
//Archivo json
import _reportes from "../archivos json/reportes.json";
import _vacio from "../archivos json/vacio.json";
//Exportador pdf
import * as jsPDF from 'jspdf';
//firebase
import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from '@angular/fire/firestore';
import {Observable} from 'rxjs'
import {Subject} from 'rxjs'
@Injectable({
providedIn: 'root'
})
export class ServicesService {
@Input() reportes
coleccionReporte: AngularFirestoreCollection<Reporte>;
reportess: Observable<Reporte[]>;
reportesMargis;
reportesDoc: AngularFirestoreDocument<Reporte>;
ColeccionDeReportes;
Reporte;
constructor(public firebase:AngularFirestore) {
this.reportess = firebase.collection('reporte').valueChanges();
console.log(this.reportes)
}
Component:
constructor(private reportesServices:ServicesService) { }
ngOnInit() {
this.reportesServices.reportess.subscribe(data => {this.reportesServices.reportes = data} ); //dont work
this.reportesServices.reportess.subscribe(data => {console.log(data)} ); //work
}
console.log(this.reportes)in the last line ofServicesServiceshows youundefined?