Embedding a map into my Angular 6 app service has been a bit tricky. Currently, I'm passing it as an argument when calling an init function in the service and providing it via Subject from the component after fetching data from the store. However, sometimes I encounter an issue where I receive undefined
instead of a map.
Here's a snippet of my code:
page.component.ts
export class PageComponent implements OnInit {
map$ = new Subject<Map>();
ngOnInit() {
this.store.pipe(
select(fromStore.getData)
)
.subscribe(data => {
this.mapService.doSomething(this.map$);
})
}
mapReady(map: Map) {
this.map$.next(map);
}
}
map.service.ts
export class MapService {
map: Map;
subscription$: Subscription;
doSomething(map$: Observable<Map>) {
this.subscription$ = map$.subscribe(data => {
this.map = data;
})
}
}
Are there any alternative methods to pass a map into the service?