Update Angular 2 Music Store sample to latest Angular2/angular-universal and make HTTP requests work during server-side prerendering

This commit is contained in:
SteveSandersonMS
2016-04-21 11:59:01 +01:00
parent a0c47252ca
commit 7b53e4aa55
11 changed files with 52 additions and 19 deletions

View File

@@ -13,7 +13,11 @@ export class GenreContents {
public albums: models.Album[];
constructor(http: Http, routeParam: router.RouteParams) {
http.get(`/api/genres/${ routeParam.params['genreId'] }/albums`).subscribe(result => {
// Workaround for RC1 bug. This can be removed with ASP.NET Core 1.0 RC2.
let isServerSide = typeof window === 'undefined';
let options: any = isServerSide ? { headers: { Connection: 'keep-alive' } } : null;
http.get(`/api/genres/${ routeParam.params['genreId'] }/albums`, options).subscribe(result => {
this.albums = result.json();
});
}