docs: remove unneeded code from universal example/guide (#36483)

In the past, server-side rendered apps needed to convert URLs used in
API requests to absolute when rendering on the server. Originally, this
was handled in the `universal` guide and corresponding example app by
modifying the `HeroService` to use `APP_BASE_HREF` to derive the
absolute URL.

In #28956, the guide was updated to show an improved method: Specifying
an `HttpInterceptor` that took care of converting the URLs to absolute.
That interceptor was only provided when rendering the app on the server.
By mistake, the corresponding example app was not updated along with the
guide.

Since `@nguniversal/*` v7.1.0, it is no longer necessary to convert the
URLs to absolute inside the app. This is handled in the `@nguniversal`
libs (see angular/universal#897).

This commit updates the example app to remove unnecessary code and
modifies the guide to mention the issue with absolute URLs, but explain
that developers only need to worry about it when not using one of the
`@nguniversal/*-engine` packages.

PR Close #36483
This commit is contained in:
George Kalpakas
2020-04-08 15:27:51 +03:00
committed by atscott
parent 609d81c65e
commit 1d4af3f734
3 changed files with 22 additions and 77 deletions

View File

@ -10,7 +10,7 @@ import { AppComponent } from './app.component';
ServerModule,
],
providers: [
// Add universal-only providers here
// Add server-only providers here.
],
bootstrap: [AppComponent],
})

View File

@ -1,5 +1,4 @@
import { Injectable, Inject, Optional } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs';
@ -18,14 +17,9 @@ export class HeroService {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
// #docregion ctor
constructor(
private http: HttpClient,
private messageService: MessageService,
@Optional() @Inject(APP_BASE_HREF) origin?: string) {
this.heroesUrl = `${origin || ''}${this.heroesUrl}`;
}
// #enddocregion ctor
private messageService: MessageService) { }
/** GET heroes from the server */
getHeroes(): Observable<Hero[]> {