mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
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:
@@ -13,7 +13,11 @@ export class AlbumDetails {
|
||||
public albumData: models.Album;
|
||||
|
||||
constructor(http: Http, routeParam: router.RouteParams) {
|
||||
http.get('/api/albums/' + routeParam.params['albumId']).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/albums/' + routeParam.params['albumId'], options).subscribe(result => {
|
||||
this.albumData = result.json();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,10 +24,14 @@ export class AlbumEdit {
|
||||
private _http: Http;
|
||||
|
||||
constructor(fb: FormBuilder, http: Http, routeParam: router.RouteParams) {
|
||||
// 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;
|
||||
|
||||
this._http = http;
|
||||
|
||||
var albumId = parseInt(routeParam.params['albumId']);
|
||||
http.get('/api/albums/' + albumId).subscribe(result => {
|
||||
http.get('/api/albums/' + albumId, options).subscribe(result => {
|
||||
var json = result.json();
|
||||
this.originalAlbum = json;
|
||||
(<Control>this.form.controls['Title']).updateValue(json.Title);
|
||||
@@ -37,11 +41,11 @@ export class AlbumEdit {
|
||||
(<Control>this.form.controls['AlbumArtUrl']).updateValue(json.AlbumArtUrl);
|
||||
});
|
||||
|
||||
http.get('/api/artists/lookup').subscribe(result => {
|
||||
http.get('/api/artists/lookup', options).subscribe(result => {
|
||||
this.artists = result.json();
|
||||
});
|
||||
|
||||
http.get('/api/genres/genre-lookup').subscribe(result => {
|
||||
http.get('/api/genres/genre-lookup', options).subscribe(result => {
|
||||
this.genres = result.json();
|
||||
});
|
||||
|
||||
|
||||
@@ -45,8 +45,12 @@ export class AlbumsList {
|
||||
}
|
||||
|
||||
refreshData() {
|
||||
// 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;
|
||||
|
||||
var sortBy = this._sortBy + (this._sortByDesc ? ' DESC' : '');
|
||||
this._http.get(`/api/albums?page=${ this._pageIndex }&pageSize=50&sortBy=${ sortBy }`).subscribe(result => {
|
||||
this._http.get(`/api/albums?page=${ this._pageIndex }&pageSize=50&sortBy=${ sortBy }`, options).subscribe(result => {
|
||||
var json = result.json();
|
||||
this.rows = json.Data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user