Last active
November 22, 2017 15:33
-
-
Save Toxicable/81619c10dc7f06417b4244cdadf71880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ServerTransferStateModule } from '@angular/platform-server'; | |
@NgModule({ | |
imports: [ | |
AppModule, | |
ServerTransferStateModule, | |
ServerModule, | |
], | |
bootstrap: [ | |
AppComponent, | |
], | |
}) | |
export class AppServerModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TransferHttpCacheModule } from '@nguniversal/common' | |
import { BrowserTransferStateModule } from '@angular/platform-server'; | |
@NgModule({ | |
imports: [ | |
BrowserModule.withServerTransition({appId: 'app-root'}), | |
BrowserTransferStateModule, | |
HttpClientModule, | |
TransferHttpCacheModule, | |
], | |
declarations: [ | |
AppComponent, | |
], | |
providers: [], | |
bootstrap: [AppComponent], | |
}) | |
export class AppModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', () => { | |
platformBrowserDynamic().bootstrapModule(AppModule); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, PLATFORM_ID , Inject} from '@angular/core'; | |
import { isPlatformServer } from '@angular/common' | |
import { TransferState , makeStateKey} from '@angular/platform-browser'; | |
import { HttpClient } from '@angular/common/http' | |
interface CounterState { | |
count: number; | |
} | |
const COUNTER_KEY = makeStateKey<CounterState>('my-counter'); | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
{{counter | json}} | |
`, | |
styles: [] | |
}) | |
export class AppComponent { | |
counter: CounterState; | |
constructor( | |
private transferState: TransferState, | |
private http: HttpClient, | |
@Inject(PLATFORM_ID) private platformId: any, | |
){} | |
ngOnInit(){ | |
this.transferState.onSerialize(COUNTER_KEY, () => this.counter); | |
this.counter = this.transferState.get(COUNTER_KEY, {count: 0}); | |
if(isPlatformServer(this.platformId)){ //isPlatformServer check is unneeded if you use `TransferHttpCacheModule` | |
this.http.get('https://jsonplaceholder.typicode.com/posts/1') | |
.subscribe(a => ++this.counter.count) | |
} | |
} | |
} |
Hi Am getting error when using
import { TransferState, makeStateKey } from '@angular/platform-browser';
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Toxicable,
Am using the angular universal cli 1.0.0-alpha.universal.3,
ServerTransferStateModule, BrowserTransferStateModule and BrowserModule.withServerTransition({appId: 'app-root'}), are not importing form node-modules
Issue: angular/angular-cli#8476
Versions:
"@angular/platform-browser": "2.2.3",
"@angular/platform-browser-dynamic": "2.2.3",
"@angular/platform-server": "^2.2.3",
Can you please help me for this