<!DOCTYPE html>
<html>
<head>
<!-- Set the base href -->
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Router Sample</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Polyfill(s) for older browsers -->
<script src="https://npmcdn.com/core-js/client/shim.min.js"></script>
<script src="https://npmcdn.com/zone.js@0.6.21?main=browser"></script>
<script src="https://npmcdn.com/reflect-metadata@0.1.3"></script>
<script src="https://npmcdn.com/systemjs@0.19.27/dist/system.src.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.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>
<!--
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
-->
</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'; // lock in the angular package version; do not let it float to current!
var routerVer = '@3.0.0'; // lock router version
//map tells the System loader where to look for things
var map = {
'app': 'src',
'@angular': 'https://unpkg.com/@angular', // sufficient if we didn't pin the version
'@angular/router': 'https://unpkg.com/@angular/router' + routerVer,
'angular2-in-memory-web-api': 'https://unpkg.com/angular2-in-memory-web-api', // get latest
'rxjs': 'https://unpkg.com/rxjs@5.0.0-beta.6',
'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',
};
//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.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' };
});
packages['@angular/router'] = { main: 'bundles/router.umd.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
*/
import {adapter} from './adapter';
import {App} from './app';
angular.module('ng1App', [])
.directive('myApp', function() {
return {
template: '<ng2></ng2>'
}
})
.directive('ng2', adapter.downgradeNg2Component(App));
adapter.bootstrap(document.body, ['ng1App']).ready(function(){
console.log('bootstrapped!');
});
import { Component, ApplicationRef } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'ng2-app',
template: `
<a [routerLink]="['/']">Home</a> |
<a [routerLink]="['/away']">Away</a>
<br><br>
<router-outlet></router-outlet>
`
})
export class App {
constructor(private router: Router) {}
ngOnInit() {
this.router.initialNavigation();
}
}
import {Component} from '@angular/core';
import {adapter} from './adapter';
@Component({
selector: 'home',
template: `
Welcome Home
`,
directives: []
})
export class Home{ }
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
import {Routes} from '@angular/router';
import {Home} from './Home';
import {Away} from './Away';
export const routes: Routes = [
{ path: '', component: Home },
{ path: 'away', component: Away }
];
export const appRouterProviders = [
];
import {Component} from '@angular/core';
@Component({
selector: 'away',
template: `
See you soon!
`
})
export class Away{ }
//our root app component
import {NgModule, ApplicationRef} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouterModule} from '@angular/router';
import {App} from './app';
import {Home} from './Home';
import {Away} from './Away';
import {routes} from './app.routes';
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
declarations: [
App,
Home,
Away
],
providers: [
{
provide: ApplicationRef,
useValue: {
componentTypes: [App],
registerDisposeListener: () => {}
}
}
]
})
export class AppModule {}
import {forwardRef} from '@angular/core';
import {UpgradeAdapter} from '@angular/upgrade';
import {AppModule} from './app.module';
export const adapter = new UpgradeAdapter(forwardRef(() => AppModule));