0
export function singleMapServiceFactory(mapServiceFactory: MapServiceFactory) 
{
   return mapServiceFactory.switchSingleMapService().subscribe((service)=>{
       return service
   })
   // return service;
}

the above code is a angular provider factory, I hope to return the 'service', but it is inside an observable, how can i do that? thanks very much

dyh333
  • 385
  • 1
  • 5
  • 15

1 Answers1

0

Consider returning an observable instead of a service object itself. Then you can subscribe to the observable in the calling function to get the service object.

   export function singleMapServiceFactory(mapServiceFactory: MapServiceFactory) 
    {
       // return an observable;
       return mapServiceFactory.switchSingleMapService()

    }

    function callingFunction(mapServiceFactory){
       singleMapServiceFactory(mapServiceFactory).subscribe((service)=>{
           //Here goes your logic
       })

    }
Shanil Fernando
  • 1,302
  • 11
  • 13