<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.8.18/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.10/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.20.19/dist/system.src.js"></script>
<script scr="https://unpkg.com/plugin-typescript@7.1.0/lib/plugin.js"></script>
<!--<script src="https://unpkg.com/core-js/client/shim.min.js"></script>-->
<!--<script src="https://unpkg.com/zone.js@0.7.4?main=browser"></script>-->
<!--<script src="https://unpkg.com/reflect-metadata@0.1.8"></script>-->
<!--<script src="https://unpkg.com/systemjs@0.19.39/dist/system.src.js"></script>-->
<!--<script src="systemjs.config.js"></script>-->
<script>
SystemJS.config({
transpiler: 'ts',
typescriptOptions: {
// Copy of compiler options in standard tsconfig.json
"target": "es5",
"module": "system",
// "module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
'npm:': 'https://unpkg.com/'
},
packages: {
'ts': {
'main': 'lib/plugin.js'
},
'typescript': {
'main': 'lib/typescript.js',
'meta': {
'lib/typescript.js': {
'exports': 'ts'
}
}
}
},
map: {
// Typescript
'ts': 'npm:plugin-typescript',
'typescript': 'npm:typescript',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// Rxjs and friends
'rxjs': 'npm:rxjs',
},
});
Promise.all([
SystemJS.import('@angular/platform-browser-dynamic'),
function() {
return "";
}
])
.then(function(imports) {
// console.log(imports);
// var platform = imports[0];
// var app = imports[1];
// platform.platformBrowserDynamic().bootstrapModule(app.AppModule);
});
SystemJS.import('script.ts').catch(function(err) {
console.error(err);
});
</script>
</head>
<body>
<h1>Hello Plunker!</h1>
<smelly id="12345">loading...</smelly>
</body>
</html>
import { NgModule, Component, SystemJsNgModuleLoader, Compile, ReflectiveInjector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
@NgModule({
imports: [BrowserModule],
providers: [SystemJsNgModuleLoader]
})
export class AppModule {
ngDoBootstrap() {}
}
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(initializeLoader)
.then(createComponent)
.then(logResult);
function initializeLoader(app) {
return {
injector: ReflectiveInjector.resolveAndCreate([], app.injector),
loader: app.injector.get(SystemJsNgModuleLoader)
};
}
function createComponent(app) {
return app.loader.load('dynamic.module.ts#DynamicModule')
.then(function(factory) {
console.log(factory);
const dynamicModule = factory.create(app.injector);
return dynamicModule
.componentFactoryResolver
.resolveComponentFactory( dynamicModule.instance.componentClass() )
.create(dynamicModule.injector, [], document.getElementById(12345));
});
}
function logResult(result) {
// console.log(result);
}
/**
* WEB ANGULAR VERSION
* (based on systemjs.config.js in angular.io)
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
SystemJS.config({
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
// Copy of compiler options in standard tsconfig.json
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
meta: {
'typescript': {
"exports": "ts"
}
},
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'ts': 'npm:plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'npm:typescript@2.0.3/lib/typescript.js',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
}
}
});
if (global.autoBootstrap) { bootstrap(); }
// Bootstrap with a default `AppModule`
// ignore an `app/app.module.ts` and `app/main.ts`, even if present
// This function exists primarily (exclusively?) for the QuickStart
function bootstrap() {
console.log('Auto-bootstrapping');
// Stub out `app/main.ts` so System.import('app') doesn't fail if called in the index.html
SystemJS.set(SystemJS.normalizeSync('app/main.ts'), SystemJS.newModule({ }));
// bootstrap and launch the app (equivalent to standard main.ts)
Promise.all([
SystemJS.import('@angular/platform-browser-dynamic'),
getAppModule()
])
.then(function (imports) {
var platform = imports[0];
var app = imports[1];
platform.platformBrowserDynamic().bootstrapModule(app.AppModule);
})
.catch(function(err){ console.error(err); });
}
// Make the default AppModule
// returns a promise for the AppModule
function getAppModule() {
console.log('Making a bare-bones, default AppModule');
return Promise.all([
SystemJS.import('@angular/core'),
SystemJS.import('@angular/platform-browser'),
SystemJS.import('app/app.component')
])
.then(function (imports) {
var core = imports[0];
var browser = imports[1];
var appComp = imports[2].AppComponent;
var AppModule = function() {}
AppModule.annotations = [
new core.NgModule({
imports: [ browser.BrowserModule ],
declarations: [ appComp ],
bootstrap: [ appComp ]
})
]
return {AppModule: AppModule};
})
}
})(this);
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
import { NgModule } from '@angular/core';
import { DynamicComponent } from './dynamic.component.ts';
@NgModule({
declarations: [DynamicComponent],
entryComponents: [DynamicComponent]
})
export class DynamicModule {
componentClass() {
return DynamicComponent;
}
}
import { Component } from '@angular/core';
@Component({
selector: 'smelly',
template: '<p>farts smell'
})
export class DynamicComponent {
}