I have a method takes it part of form management and does the things below. I can solve a case like this with promises easily, but here is the time to learn observables! So, the tasks of the method:
- calls clientWebApiService.getClients()to get clients list, and returns observable ofenvironmentWebApiService.getEnvironmentsNotInPipeline()
- in the second flatMap the result will be passed to local variable
- in the subscribeI would like to map a data structure another to be able to setup things of a form
The subscribe() throws the error below:
ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at Object.subscribeToResult (subscribeToResult.js:73)
    at MergeMapSubscriber._innerSub (mergeMap.js:130)
    at MergeMapSubscriber._tryNext (mergeMap.js:127)
I already (hopefully) figured out that subscribe expects a stream which is not provided here. If I see correctly the second flatMap should return an Observable which is processed by the subscribe(). In this structure there will be no. In this case what method should be called? I found the rxjs documentation with lot of methods. I don't know which one I'm looking for.
I have tried to restructure my code, but if there is no subscribe(), then there is no execution.
- what is the best practice case like this?
public editHandler({ dataItem }): void {
        let clients: IClientContract[];
        let environments: IEnvironmentContract[];
        this.clientWebApiService.getClients()
            .flatMap((clientsResult: any): Observable<IEnvironmentContract[]> => {
                clients = clientsResult as IClientContract[];
                console.log('1', clients);
                return this.environmentWebApiService.getEnvironmentsNotInPipeline();
            })
            .flatMap((environmentResult: IEnvironmentContract[]): any => {
                environments = environmentResult;
                console.log('2', environments);
            })
            .subscribe(() => {
                console.log('3');
                let editableDeploymentItem: IDeployableEnvironmentForm = this.deployableEnvironmentContractMapperService
                    .mapDeployableEnvironmentContractToDeployableEnvironmentForm(
                    dataItem,
                    clients,
                    environments);
                console.log('4', editableDeploymentItem);
                this.editDeployment = editableDeploymentItem;
                this.isNew = false;
            });
    }
 
     
     
    