我正在使用Angular 4 Server端渲染,并遇到了所有服务调用都需要绝对URL的问题。
我正在尝试使用" ORIGIN_URL"正如我的研究中所指出的那样。
这是我的app.module:
set(foo)
我试图将此ORGIN_URL注入服务以获取绝对URL。 这是我的服务:
import { NgModule, ErrorHandler, Inject, InjectionToken } from
'@angular/core';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouteReuseStrategy } from '@angular/router';
import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
import { Title } from '@angular/platform-browser';
import { LinkService } from './../shared/page/link.service';
// Main App Root Component
import { AppComponent } from './app.component';
import { ROUTES } from './app.routes';
// Component imports
import { HeaderComponent } from './../global-components/header/header.component';
import { FooterComponent } from './../global-components/footer/footer.component';
import { LogInComponent } from './../global-components/login/log-in.component';
// Provider (aka: "shared" | "services") imports
import { LoggingHttpService } from './../shared/application-error-handler/logging.http.service';
// i18n support
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ORIGIN_URL } from '@nguniversal/aspnetcore-engine';
...
export function createTranslateLoader(http: HttpClient, baseHref) {
// Temporary Azure hack
if (baseHref === null && typeof window !== 'undefined') {
baseHref = window.location.origin;
}
// i18n files are in `wwwroot/assets/`
return new TranslateHttpLoader(http, `${baseHref}/assets/i18n/`, '.json');
}
@NgModule({
declarations: [
AppComponent,
// put shared components here
HeaderComponent,
FooterComponent,
LogInComponent,
],
imports: [
CommonModule,
HttpModule,
RouterModule,
FormsModule,
RouterModule.forRoot(ROUTES),
ReactiveFormsModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient, [ORIGIN_URL]]
}
})
...
],
providers: [
LinkService,
// put shared services here
LoggingHttpService,
...
TranslateModule
],
entryComponents: [
...
]
})
export class AppModule {}
我收到错误Angular 4没有提供者注入FeedToken ORIGIN_URL!
答案 0 :(得分:1)
ORIGIN_URL
和REQUEST
被移动@nguniversal/aspnetcore-engine/
到@nguniversal/aspnetcore-engine/tokens
您可以导入
import { ORIGIN_URL, REQUEST } from '@nguniversal/aspnetcore-engine/tokens';