<!DOCTYPE html>
<html>
<html>
<head>
<!-- Set the base href -->
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Component outlet example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.12?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app')
.catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
/**
* PLUNKER VERSION (based on systemjs.config.js in angular.io)
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function(global) {
var ngVer = '@2.0.0-rc.6'; // lock in the angular package version; do not let it float to current!
var routerVer = '@3.0.0-rc.2'; // lock router version
var routerDeprecatedVer = '@2.0.0-rc.2'; // temporarily until we update all the guides
//map tells the System loader where to look for things
var map = {
'app': 'app',
'@angular': 'https://unpkg.com/@angular', // sufficient if we didn't pin the version
'@angular/router': 'https://unpkg.com/@angular/router' + routerVer,
'@angular/forms': 'https://unpkg.com/@angular/forms' + ngVer,
'@angular/router-deprecated': 'https://unpkg.com/@angular/router-deprecated' + routerDeprecatedVer,
'angular2-in-memory-web-api': 'https://unpkg.com/angular2-in-memory-web-api', // get latest
'rxjs': 'https://unpkg.com/rxjs@5.0.0-beta.11',
'ts': 'https://unpkg.com/plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'https://unpkg.com/typescript@1.9.0-dev.20160409/lib/typescript.js',
'angular2-component-outlet': 'https://unpkg.com/angular2-component-outlet@0.1.2/index.js',
};
//packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.ts', defaultExtension: 'ts' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
};
var ngPackageNames = [
'common',
'compiler',
'core',
'http',
'platform-browser',
'platform-browser-dynamic',
'upgrade',
];
// Add map entries for each angular package
// only because we're pinning the version with `ngVer`.
ngPackageNames.forEach(function(pkgName) {
map['@angular/'+pkgName] = 'https://unpkg.com/@angular/' + pkgName + ngVer;
});
// Add package entries for angular packages
ngPackageNames.concat(['forms', 'router', 'router-deprecated']).forEach(function(pkgName) {
// Bundled (~40 requests):
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
// Individual files (~300 requests):
//packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
map: map,
packages: packages
};
System.config(config);
})(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
*/
/* Master Styles */
h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
}
h2, h3 {
color: #444;
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
body {
margin: 2em;
}
body, input[text], button {
color: #888;
font-family: Cambria, Georgia;
}
a {
cursor: pointer;
cursor: hand;
}
button {
font-family: Arial;
background-color: #eee;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
cursor: hand;
}
button:hover {
background-color: #cfd8dc;
}
button:disabled {
background-color: #eee;
color: #aaa;
cursor: auto;
}
/* Navigation link styles */
nav a {
padding: 5px 10px;
text-decoration: none;
margin-top: 10px;
display: inline-block;
background-color: #eee;
border-radius: 4px;
}
nav a:visited, a:link {
color: #607D8B;
}
nav a:hover {
color: #039be5;
background-color: #CFD8DC;
}
nav a.active {
color: #039be5;
}
/* items class */
.items {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: 24em;
}
.items li {
cursor: pointer;
position: relative;
left: 0;
background-color: #EEE;
margin: .5em;
padding: .3em 0;
height: 1.6em;
border-radius: 4px;
}
.items li:hover {
color: #607D8B;
background-color: #DDD;
left: .1em;
}
.items li.selected:hover {
background-color: #BBD8DC;
color: white;
}
.items .text {
position: relative;
top: -3px;
}
.items {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: 24em;
}
.items li {
cursor: pointer;
position: relative;
left: 0;
background-color: #EEE;
margin: .5em;
padding: .3em 0;
height: 1.6em;
border-radius: 4px;
}
.items li:hover {
color: #607D8B;
background-color: #DDD;
left: .1em;
}
.items li.selected {
background-color: #CFD8DC;
color: white;
}
.items li.selected:hover {
background-color: #BBD8DC;
}
.items .text {
position: relative;
top: -3px;
}
.items .badge {
display: inline-block;
font-size: small;
color: white;
padding: 0.8em 0.7em 0 0.7em;
background-color: #607D8B;
line-height: 1em;
position: relative;
left: -1px;
top: -4px;
height: 1.8em;
margin-right: .8em;
border-radius: 4px 0 0 4px;
}
/* everywhere else */
* {
font-family: Arial, Helvetica, sans-serif;
}
/*
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
*/
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { ComponentOutlet, provideComponentOutletModule } from 'angular2-component-outlet';
import { AppComponent } from './app.component';
import { DynamicComponent } from './dynamic.component';
import { NonDynamicComponent } from './non-dynamic.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
],
declarations: [
AppComponent,
ComponentOutlet,
DynamicComponent,
NonDynamicComponent
],
providers:[
provideComponentOutletModule({
imports: [
]
})
],
bootstrap: [AppComponent]
})
export class AppModule {
}
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1 class="title">Test component outlet</h1>
<div style="margin-bottom: 5px;">
<button (click)="addComponent()">Add dynamic component</button>
</div>
<div *ngFor="let name of names">
<p>Component {{name}}:</p>
<ul>
<li><dynamic-component id='{{name}}'></dynamic-component></li>
<li><non-dynamic-component id='{{name}}'></non-dynamic-component></li>
</ul>
</div>
`
})
export class AppComponent {
public names = [];
private id = 0;
addComponent(){
this.names.push(`${++this.id}`);
}
}
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'dynamic-component',
template: `
<span *componentOutlet="template; context: self; selector:'dynamic-component'"></span>
`,
})
export class DynamicComponent implements OnInit {
@Input() id: string;
self = this;
template: string = '';
ngOnInit() {
console.warn(`DynamicComponent.onInit:${this.id}`)
this.self = this;
this.template = `<span>Dynamic component ${this.id} </span>`;
}
}
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'non-dynamic-component',
template: `
<span>Non dynamic {{id}}</span>
`,
})
export class NonDynamicComponent implements OnInit {
@Input() id: string;
ngOnInit() {
console.warn(`NonDynamicComponent.onInit:${this.id}`)
}
}