Skip to content

Instantly share code, notes, and snippets.

@ismcagdas
Created January 29, 2018 12:21
Show Gist options
  • Save ismcagdas/e4161800c514099782215ad042e77aa7 to your computer and use it in GitHub Desktop.
Save ismcagdas/e4161800c514099782215ad042e77aa7 to your computer and use it in GitHub Desktop.
Acme.HeroShop - app.module.ts
import { BrowserTransferStateModule } from '../modules/transfer-state/browser-transfer-state.module';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ORIGIN_URL, REQUEST } from '@nguniversal/aspnetcore-engine';
export function getOriginUrl() {
return window.location.origin;
}
export function getRequest() {
// the Request object only lives on the server
return { cookie: document.cookie };
}
@NgModule({
declarations: [
AppComponent
],
imports: [
// To support Universal rendering. The application ID can be any identifier which is unique on the page.
BrowserModule.withServerTransition({ appId: 'my-app-site' }),
BrowserModule,
BrowserTransferStateModule,
AppRoutingModule,
FormsModule
],
providers: [{
// We need this for our Http calls since they'll be using an ORIGIN_URL provided in main.server
// (Also remember the Server requires Absolute URLs)
provide: ORIGIN_URL,
useFactory: getOriginUrl
}, {
// The server provides these in main.server
provide: REQUEST,
useFactory: getRequest
}],
bootstrap: [AppComponent]
})
export class AppModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment