diff --git a/templates/AngularSpa/ClientApp/app/app.module.client.ts b/templates/AngularSpa/ClientApp/app/app.module.client.ts index ee77812..f5360ae 100644 --- a/templates/AngularSpa/ClientApp/app/app.module.client.ts +++ b/templates/AngularSpa/ClientApp/app/app.module.client.ts @@ -14,7 +14,8 @@ import { sharedConfig } from './app.module.shared'; ...sharedConfig.imports ], providers: [ - { provide: 'ORIGIN_URL', useValue: location.origin } + { provide: 'ORIGIN_URL', useValue: location.origin }, + { provide: 'PRERENDERING_DATA', useValue: (window as any).PRERENDERING_DATA } ] }) export class AppModule { diff --git a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.html b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.html index 8d24e71..1fadc50 100644 --- a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.html +++ b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.html @@ -1,5 +1,7 @@

Weather forecast

+

Prerendering data: {{ prerenderingDataString }}

+

This component demonstrates fetching data from the server.

Loading...

diff --git a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts index 9c98b76..e49cf86 100644 --- a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts +++ b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts @@ -7,8 +7,11 @@ import { Http } from '@angular/http'; }) export class FetchDataComponent { public forecasts: WeatherForecast[]; + public prerenderingDataString: string; + + constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string, @Inject('PRERENDERING_DATA') prerenderingData: any) { + this.prerenderingDataString = JSON.stringify(prerenderingData); - constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string) { http.get(originUrl + '/api/SampleData/WeatherForecasts').subscribe(result => { this.forecasts = result.json() as WeatherForecast[]; }); diff --git a/templates/AngularSpa/ClientApp/boot-server.ts b/templates/AngularSpa/ClientApp/boot-server.ts index 08474cf..3fbe2ba 100644 --- a/templates/AngularSpa/ClientApp/boot-server.ts +++ b/templates/AngularSpa/ClientApp/boot-server.ts @@ -11,7 +11,8 @@ enableProdMode(); export default createServerRenderer(params => { const providers = [ { provide: INITIAL_CONFIG, useValue: { document: '', url: params.url } }, - { provide: 'ORIGIN_URL', useValue: params.origin } + { provide: 'ORIGIN_URL', useValue: params.origin }, + { provide: 'PRERENDERING_DATA', useValue: params.data } ]; return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => { @@ -26,7 +27,8 @@ export default createServerRenderer(params => { // completing the request in case there's an error to report setImmediate(() => { resolve({ - html: state.renderToString() + html: state.renderToString(), + globals: { PRERENDERING_DATA: params.data } }); moduleRef.destroy(); }); diff --git a/templates/AngularSpa/Views/Home/Index.cshtml b/templates/AngularSpa/Views/Home/Index.cshtml index fc1ae58..ba50ddb 100644 --- a/templates/AngularSpa/Views/Home/Index.cshtml +++ b/templates/AngularSpa/Views/Home/Index.cshtml @@ -2,7 +2,11 @@ ViewData["Title"] = "Home Page"; } -Loading... +Loading... @section scripts {