import { bootstrap, onChange, NgIf, NgFor, Component, Directive, View, Ancestor, NgValidator, forwardRef, Binding, EventEmitter } from 'angular2/angular2'; import {formDirectives} from 'angular2/forms'; import {ListWrapper} from 'angular2/src/facade/collection'; import {reflector} from 'angular2/src/reflection/reflection'; import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; /** * You can find the Angular 1 implementation of this example here: * https://github.com/wardbell/ng1DataBinding */ // ---- model class OrderItem { constructor(public orderItemId: number, public orderId: number, public productName: string, public qty: number, public unitPrice: number) {} get total(): number { return this.qty * this.unitPrice; } } class Order { constructor(public orderId: number, public customerName: string, public limit: number, private dataService: DataService) {} get items(): OrderItem[] { return this.dataService.itemsFor(this); } get total(): number { return this.items.map(i => i.total).reduce((a, b) => a + b); } } // ---- services var _nextId = 1000; class DataService { orderItems: OrderItem[]; orders: Order[]; currentOrder: Order = null; constructor() { this.orders = [ new Order(_nextId++, "J. Coltrane", 100, this), new Order(_nextId++, "B. Evans", 200, this) ]; this.orderItems = [ new OrderItem(_nextId++, this.orders[0].orderId, "Bread", 5, 1), new OrderItem(_nextId++, this.orders[0].orderId, "Brie", 5, 2), new OrderItem(_nextId++, this.orders[0].orderId, "IPA", 5, 3), new OrderItem(_nextId++, this.orders[1].orderId, "Mozzarella", 5, 2), new OrderItem(_nextId++, this.orders[1].orderId, "Wine", 5, 3) ]; } itemsFor(order: Order): OrderItem[] { return ListWrapper.filter(this.orderItems, i => i.orderId === order.orderId); } addItemForOrder(order: Order): void { this.orderItems.push(new OrderItem(_nextId++, order.orderId, "", 0, 0)); } deleteItem(item: OrderItem): void { ListWrapper.remove(this.orderItems, item); } } // ---- components @Component({selector: 'order-list-cmp'}) @View({ template: `