Skip to content

Instantly share code, notes, and snippets.

@noisy
Created November 7, 2015 11:12
Show Gist options
  • Save noisy/b5d855da3db3f5db238e to your computer and use it in GitHub Desktop.
Save noisy/b5d855da3db3f5db238e to your computer and use it in GitHub Desktop.
import {Component, Input, bootstrap, CORE_DIRECTIVES} from 'angular2/angular2';
import {Product, SpecialProduct} from './products.ts';
@Component({
selector: 'my-tile',
directives: [CORE_DIRECTIVES],
template: `
<div class="col col-xs-6 col-md-4 col-lg-2">
<div class="panel panel-default">
<img src="{{ item.graphic }}" class="img-responsive" />
<div class="panel-body">
<header class="text-center"><h3>{{ item.name }}</h3></header>
</div>
</div>
</div>
`
})
class Tile {
@Input() item: Product;
}
@Component({
selector: 'my-app',
directives: [CORE_DIRECTIVES, Tile],
template:
`
<div>
<div *ng-for="#item of items">
<my-tile [item]="item"></my-tile>
</div>
</div>
`
})
class AppComponent {
items: Product[];
constructor() {
this.items = [
new Product('Orange', 2, 'juicy orange', 'http://psdreview.com/wp-content/uploads/2012/02/How-to-Make-a-Delicious-Vector-Orange-in-9-Decisive-Steps.jpg'),
new Product('Banana', 4, 'Le banaba!', 'http://cdn.shopify.com/s/files/1/0395/4113/products/banan_8f43351d-4cd9-4c4d-9daf-e20749276749_large.jpg?v=1417774878'),
new Product('Blue Raspberry', 10, 'Delicious blue raspberry', 'http://www.hoosiervapes.com/thumbnail.asp?file=assets/images/bluerasp.jpg&maxx=500&maxy=0'),
]
this.items.push(new SpecialProduct('Basket of Fruts', 100, 'Basket of Fresh Fruits!', 'https://lh4.ggpht.com/gkcBkx0wqL8PsmjncQhs3TJY1J3LpZpAH6ziKG7FAkqgXcyM1FAtU9d_rteVRZwN7rUZ=h900'));
}
}
bootstrap(AppComponent, []);
<html>
<head>
<title>Angular 2 QuickStart</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script src="/cdn/angular.js/2.0.0-alpha.45/tools/system.js"></script>
<script src="/cdn/angular.js/2.0.0-alpha.45/tools/typescript.js"></script>
<script src="/cdn/angular.js/2.0.0-alpha.45/angular2.dev.js"></script>
<script src="/cdn/angular.js/2.0.0-alpha.45/http.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true }
});
System.import('./src/app.ts');
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
export class Product {
constructor(public name:string, public price:number, public desc:string, public graphic:string) {
}
}
export class SpecialProduct extends Product {
public special:string;
constructor(public name:string, public price:number, public desc:string, public graphic:string){
super(name, price, desc, grap);
this.special = "SUPER!! :)";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment