<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<link rel="stylesheet" href="style.css" />
<script src="https://npmcdn.com/zone.js@0.6.12/dist/zone.js"></script>
<script src="https://npmcdn.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://npmcdn.com/systemjs@0.19.31/dist/system.js"></script>
<script src="https://npmcdn.com/typescript@1.8.10/lib/typescript.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
map: {
app: "./src",
'@angular': 'https://npmcdn.com/@angular',
'rxjs': 'https://npmcdn.com/rxjs@5.0.0-beta.6'
},
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'
},
rxjs: {
defaultExtension: 'js'
}
}
});
System
.import('app')
.catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>
loading...
</my-app>
</body>
</html>
/* Styles go here */
### Angular2 Starter Plunker - Typescript - RC.0
A simple plunker demonstrating Angular2 usage:
- Uses SystemJS + TypeScript to compile on the fly
- Includes binding, directives, http, pipes, and DI usage.
import {bootstrap} from '@angular/platform-browser-dynamic';
import App from './app';
bootstrap(App, [])
.catch(err => console.error(err));
import {Component} from '@angular/core';
interface Grocery {
id: number;
label: string;
}
@Component({
selector: 'my-app',
template: `
<div>
Search Term: <input type="text" [(ngModel)]="searchTerm">
<ul>
<li *ngFor="let grocery of orderedGroceries">
<a>{{ grocery.label | uppercase }}</a>
</li>
</ul>
</div>
`
})
export default class App {
searchTerm: string;
public groceries: Grocery[];
constructor() {
this.groceries = [{
id: 0, label: 'Butter'
},{
id: 1, label: 'Apples'
},{
id: 2, label: 'Paprika'
},{
id: 3, label: 'Potatoes'
},{
id: 4, label: 'Oatmeal'
},{
id: 5, label: 'Spaghetti'
},{
id: 6, label: 'Pears'
},{
id: 7, label: 'Bacon'
}];
}
get orderedGroceries {
var filtered = this.groceries.filter((grocery) => {
if (this.searchTerm && this.searchTerm.length > 0) {
return grocery.label.toUpperCase().indexOf(this.searchTerm.toUpperCase(), 0) > -1;
}
else {
return true;
}
});
return filtered.sort((a, b) => {
var textA = a.label.toUpperCase();
var textB = b.label.toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
});
}
}