/
order.component.ts
59 lines (48 loc) · 1.43 KB
/
order.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {Component, Input, OnInit} from '@angular/core';
import {NavController, Refresher} from 'ionic-angular';
import {Observable} from 'rxjs/Observable';
import {DetailComponent} from '../detail/detail.component';
import {CartComponent} from '../cart/cart.component';
import {PizzaService, CartService} from '../../providers';
import {Pizza} from '../../models';
@Component({
templateUrl: 'order.component.html',
})
export class OrderComponent implements OnInit {
pizzas: Pizza[] = [];
loading: boolean;
pizzaSource: Observable<Pizza[]>;
@Input() search: string = "";
constructor(
private pizzaService: PizzaService,
private cartService: CartService,
private nav: NavController
) {}
ngOnInit() {
this.loading = true;
const subscription = this.pizzaService.getPizzas().subscribe(pizzas => {
this.pizzas = pizzas;
this.loading = false;
subscription.unsubscribe();
}, () => this.loading = false);
}
doRefresh(refresher: Refresher) {
const subscription = this.pizzaService.getPizzas().subscribe(pizzas => {
this.pizzas = pizzas;
refresher.complete()
subscription.unsubscribe();
}, () => refresher.complete());
}
openPizza(id: number) {
this.nav.push(DetailComponent, {
id: id
});
}
openCart() {
this.nav.push(CartComponent);
}
addToCart($event, pizza: Pizza) {
$event.stopPropagation();
this.cartService.addCartItem(pizza);
}
}