Skip to content

reactive X

Not really only angular, but since I use it mostly there.

synchronous get.

Almost all backend calls are returning an observable and follow this pattern..

  • call http.get() and return an observable, or directly subscribe to it.
  • else subscribe to the returned observable to handle the data, then call notify.
  • notify usually then triggers (call .next()) on a Subject() observable (order.$changed for example)
  • various components have subscribed to that Subject (orderset for instance) causing the data te be redrawn.

When we really want to wait for the http.get() data to be ready, this pattern can be used.

 public async readConfigs(): Promise<any> {

        ...

        const msg = await this.http.get(apiUrl,options).toPromise();

        // possible extract the data 
        let payload = msg['payload'];
        this.config = payload;
        return this.config;
 }

We should call readConfigs() like this :

     this.confservice.readConfigs().then( (result) => {
            console.log(result);
            this.config=result;
            console.log(this.config.start); // or do things with config
     })

I wrote this down because again, config is better usable if we also make an Subject + observable from it and let components subscribe to it.

It could very well be that this approach should always be used ?!