<!DOCTYPE html>
<html>
<head>
<title>Angular2 @Input</title>
<link rel="stylesheet" href="style.css" />
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="config.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.15/http.dev.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 Starter Plunker - Typescript - Beta 0
A simple plunker demonstrating Angular2 usage:
- Uses SystemJS + TypeScript to compile on the fly
- Includes binding, directives, http, pipes, and DI usage.
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"
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
}
}
});
//main entry point
import {bootstrap} from 'angular2/platform/browser';
import {App} from './app';
bootstrap(App, [])
.catch(err => console.error(err));
//our root app component
import {Component} from 'angular2/core'
import {ObjectViewComponent} from './object-view.component'
@Component({
selector: 'my-app',
templateUrl: './my-template.html',
directives: [ObjectViewComponent]
})
export class App {
private object: any = {
string: 'string',
boolean: true,
number: 0,
array: ['a', 'b', 'c'],
object: {
prop1: 'prop1',
prop2: 100
prop3: {
array: ['999', '998', '997']
}
}
}
}
import {Component, Input} from 'angular2/core'
@Component({
selector: 'object-view',
template: `<ul>
<li *ngFor="#property of getKeys()">
{{property}}:
<span *ngIf="!isObject(property)">
{{getValue(property)}}
</span>
<span *ngIf="isObject(property)">
<object-view [object]="getValue(property)"></object-view>
</span>
</li>
</ul>`,
directives: [ObjectViewComponent]
})
export class ObjectViewComponent {
@Input() object: any;
private getKeys(): string[] {
return Object.keys(this.object);
}
private getValue(property: string): any {
return this.object[property];
}
private isObject(property: string): boolean {
const value = this.getValue(property);
return !Array.isArray(value) && typeof value === 'object';
}
}
<h1>test</h1>
<object-view [object]="object"></object-view>