<!DOCTYPE html>
<html>
<head>
<base href="." />
<title>angular2 playground</title>
<link rel="stylesheet" href="style.css" />
<script src="https://unpkg.com/zone.js@0.6.21/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
<script src="https://unpkg.com/typescript@1.8.10/lib/typescript.js"></script>
<script src="config.js"></script>
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>
loading...
</my-app>
</body>
</html>
/* Styles go here */
### Angular2 Change Detection Example - Typescript - RC.5
A simple plunker demonstrating how Angular2 change detection is being triggered.
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
//map tells the System loader where to look for things
map: {
app: "./src",
'@angular': 'https://npmcdn.com/@angular',
'rxjs': 'https://npmcdn.com/rxjs@5.0.0-beta.6'
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
'@angular/core': {
main: 'bundles/core.umd.js',
defaultExtension: 'js'
},
'@angular/compiler': {
main: 'bundles/compiler.umd.js',
defaultExtension: 'js'
},
'@angular/common': {
main: 'bundles/common.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser-dynamic': {
main: 'bundles/platform-browser-dynamic.umd.js',
defaultExtension: 'js'
},
'@angular/platform-browser': {
main: 'bundles/platform-browser.umd.js',
defaultExtension: 'js'
},
'@angular/forms': {
main: 'index.js',
defaultExtension: 'js'
},
'@angular/router': {
main: 'index.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app';
platformBrowserDynamic().bootstrapModule(AppModule)
//our root app component
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {RowComponent} from './row'
@Component({
selector: 'my-app',
template: `
<row *ngFor="let rowData of rows" [data]="rowData"></row>
`,
directives: [RowComponent]
})
class App {
private rows: Array<string> = [];
constructor() {
for (let i = 0; i < 100; i++) {
this.rows.push(Math.random().toString(30).substring(2, 10));
}
setInterval(() => {
this.rows[parseInt(Math.random()*100, 10)] = '--------';
}, 2500)
}
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App, RowComponent ],
bootstrap: [ App ]
})
export class AppModule {}
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
@Component({
selector: 'row',
template: `
<pre>{{ rowData }}</pre>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RowComponent {
@Input() public data: string;
get rowData(): string {
console.debug('getting row data');
return this.data;
}
ngOnChanges(): void {
console.debug('change');
}
}