(Following the suggestion so gunnar, i'm editing my question) @Gunnar.B
Service for connection with api
@Injectable({
providedIn: 'root'
})
export class ConsolidadoApi {
constructor(private http: HttpClient) { }
getInvestiments(search?: any): Observable<any> {
return this.http.get<any>(`${environment.basePosicaoConsolidada}`);
}
}
This service (layer) exposes the streams of state and interface for the components in the presentation layer(component)
@Injectable({
providedIn: 'root'
})
export class CoreService {
constructor(private api: ConsolidadoApi, private state: StateService) { }
public getInvestments$(): Observable<any> {
return this.state.getInvestiments$()
}
public loadInvestments() {
return this.api.getInvestiments()
.pipe(
tap(investPortifolio => this.state.setInvestments(investPortifolio))
);
}
}
This service is responsible for the logic that will go to the component
@Injectable({
providedIn: 'root'
})
export class StateService {
private investments$ = new BehaviorSubject<any>(null);
public getInvestiments$() {
return this.investments$.asObservable()
}
public setInvestments(investPortifolio){
this.investments$.next(investPortifolio)
}
}
However in my html does not appear the data coming from the api.
menu.component.ts
export class MenuComponent implements OnInit {
investments$: Observable<any>;
constructor( private coreService : CoreService ) {
this.investments$ = this.coreService.getInvestments$()
}
ngOnInit(): void {
this.coreService.loadInvestments();
console.log(this.coreService.loadInvestments())
}
}
menu.component.html
<div>
test
</div>
<div *ngFor="let investimentPortifolio of investments$ | async;">
{{investimentPortifolio | json}}
</div>