Example of using asp-prerender-data to get server-supplied data to both server and client JS

This commit is contained in:
Steve Sanderson
2017-05-22 10:25:08 +01:00
parent ad645cbfe9
commit 678e230021
5 changed files with 17 additions and 5 deletions

View File

@@ -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[];
});