Make templates work with nonempty baseUrls (e.g., IIS virtual directories)

This commit is contained in:
Steve Sanderson
2017-07-11 23:45:25 +01:00
parent bb0727c34c
commit e65ecebac6
31 changed files with 65 additions and 44 deletions

View File

@@ -10,12 +10,12 @@ import { AppComponent } from './components/app/app.component';
AppModuleShared
],
providers: [
{ provide: 'ORIGIN_URL', useFactory: getOriginUrl }
{ provide: 'BASE_URL', useFactory: getBaseUrl }
]
})
export class AppModule {
}
export function getOriginUrl() {
return location.origin;
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}

View File

@@ -8,8 +8,8 @@ import { Http } from '@angular/http';
export class FetchDataComponent {
public forecasts: WeatherForecast[];
constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string) {
http.get(originUrl + '/api/SampleData/WeatherForecasts').subscribe(result => {
constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
this.forecasts = result.json() as WeatherForecast[];
}, error => console.error(error));
}