Giter VIP home page Giter VIP logo

Comments (8)

peterpeterparker avatar peterpeterparker commented on May 30, 2024 1

@ysus that's good english 👍

If I may, I would just suggest to modify angular universal need to with angular universal will ... it isn't a must, that's the purpose of transfer-state ;)

from ng-universal-demo.

peterpeterparker avatar peterpeterparker commented on May 30, 2024 1

@crebuh yes so far, simple case at least, I'm only working with TransferState

from ng-universal-demo.

FrozenPandaz avatar FrozenPandaz commented on May 30, 2024

its a temporary drop in replacement for @angular/http which will store your api data retrieved by the server so that the client does not have to rerequest them

from ng-universal-demo.

jbeckton avatar jbeckton commented on May 30, 2024

oh thats slick! Does it make sense to use that api for other things in my code as well or is it just needed for the transferring of state?

from ng-universal-demo.

crebuh avatar crebuh commented on May 30, 2024

@FrozenPandaz

Is there a guide on how to use it?

from ng-universal-demo.

peterpeterparker avatar peterpeterparker commented on May 30, 2024

@crebuh basically on the server side you do your query and save the results in transfer-state and on the client side you query the transfers-state

in a provider something like:

getSomething(): Observable<Object> {
     if (isPlatformServer(this.platformId)) {
         return Observable.fromPromise(this.doGet());
    } else {
        return this.getFromTransferState();
   }
   
private doGet(itemHashId: string): Promise<{}> {
      return new Promise((resolve, reject) => {
            const params: HttpParams = new HttpParams();
    
           this.httpClient.get('http://...', {params: params}).subscribe((result: any) => {
                 this.transferState.set('my-key', result);
                 resolve(result);
           }, (error) => {
               reject(error);
          });
       });
 }

 private getFromTransferState(): Observable<Object> {
    return new Observable(observer => {
        observer.next(this.transferState.get('my-key'));
    });
  }

don't know if it's the right way or a good way but that seems to work for me

from ng-universal-demo.

ysus avatar ysus commented on May 30, 2024

angular universal will two http call, one in the server when you realize the request to generate the html render to SEO, and other call in the client when the code js is load in the browser. the purpose of transfer is to avoid the second call and transfert the info of the http call to the client. or wherever info you need to transfer to the client not only http calls

sorry for my bad enghlish.

from ng-universal-demo.

crebuh avatar crebuh commented on May 30, 2024

@peterpeterparker

thx I got this, maybe my question wasn't clear. the module offers already some methods like get, put, post.

so this was confusing me, if these are just examples inside the class. but it seems you are just working with with transferState.get and transferState.set

from ng-universal-demo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.