Comments (8)
@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.
@crebuh yes so far, simple case at least, I'm only working with TransferState
from ng-universal-demo.
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.
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.
Is there a guide on how to use it?
from ng-universal-demo.
@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.
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.
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)
- Server render global styles HOT 7
- how to build the file /ngfactory/app/server-app.module.ngfactory HOT 2
- how to add images to pages? HOT 3
- Adding mongoose HOT 3
- aot with universal
- Router resolve with the TransferHttp module
- onBootstrap HOT 1
- How can you access location/url information on the server angular app HOT 3
- Error in starting server HOT 3
- Error compiling Scss with npm run build:aot HOT 1
- Problem with assets folder HOT 2
- The server not start HOT 1
- Angular Express Engine service error
- Can't get SASS to work. HOT 1
- Appengine deploy failing HOT 1
- Setting State
- HttpClient HOT 1
- How to make HTTP calls on the server-side inside a lazy loaded module
- security issue with server bundle output
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-universal-demo.