: 22 2016 .
Angular 2.1 AOT (https://angular.io/docs/ts/latest/cookbook/aot-compiler.html) .
<script>window.module = 'aot';</script>
index.html aot.
TL;DR
, , , , , .
: rollup-module.provider.ts
export function RollupModuleProvider(params: any) {
return function (target: any) {
try {
let testIfRunningWithCommonJSandModuleIsAvailable = module.id;
} catch (e) {
console.log("Defining Module");
var globalScope: any;
if (typeof window === 'undefined') {
globalScope = global;
}
else {
globalScope = window;
}
globalScope.module = "test";
try {
let moduleShouldBeAvailable = module;
}
catch (e) {
console.error("Module not defined");
}
}
}
}
app.component.ts . , app.component.ts , "bootstrap" app.module.ts.
import {RollupModuleProvider} from "./rollup-module.provider";
@RollupModuleProvider({})
app.component.ts . . . "" html "templateUrl", html . , app.component.ts, /.
import { Component } from '@angular/core';
import './rxjs-operators';
import {ModalService} from "./shared/modal.service";
import {RollupModuleProvider} from "./rollup-module.provider";
@RollupModuleProvider({})
@Component({
selector: 'myapp',
template:
`<div [class.modalDisplayed]="modalService.isModalDisplayed()"></div>
<nav-header></nav-header>
<div class="container-fluid">
<router-outlet> </router-outlet>
</div>`
})
export class AppComponent {
constructor (public modalService: ModalService) {
}
}
app.module.ts.
import {NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { routing } from './app.routing';
import { Logger } from './logger.service';
import { HttpClient } from './http.client.service';
import {WindowSize} from './window-size.service';
import {ModalService} from "./shared/modal.service";
import {SharedModule} from "./shared/shared.module";
@NgModule({
imports: [BrowserModule, HttpModule, routing, SharedModule],
declarations: [AppComponent],
providers: [ Logger, HttpClient, WindowSize, ModalService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
moduleId , tsc commonjs . AoT moduleId. UncaughtReferenceError AoT, "", ( JavaScript). commonjs , .
AoT , , AoT. , , , .
- Angular 2, .