Skip to content

Commit 714fce7

Browse files
author
Kim Maida
committed
Add private deals. Moved purchase function into the deals service.
1 parent 0a226b5 commit 714fce7

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

ng2auth/src/app/deal.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ export class DealService {
3636
console.error('An error occurred', err);
3737
return Observable.throw(err.message || err);
3838
}
39+
40+
purchase(item) {
41+
alert(`You bought the: ${item.name}`);
42+
}
3943
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.panel-body {
2+
min-height: 100px;
3+
}
Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1-
<p>
2-
private-deals works!
3-
</p>
1+
<h3 class="text-center">Special (Private) Deals</h3>
2+
3+
<div class="col-sm-4" *ngFor="let deal of privateDeals">
4+
<div class="panel panel-default">
5+
<div class="panel-heading">
6+
<h3 class="panel-title">{{ deal.name }}</h3>
7+
</div>
8+
<div class="panel-body">
9+
{{ deal.description }}
10+
</div>
11+
<div class="panel-footer">
12+
<ul class="list-inline">
13+
<li>Original</li>
14+
<li class="pull-right">Sale</li>
15+
</ul>
16+
<ul class="list-inline">
17+
<li><a class="btn btn-danger">${{ deal.originalPrice | number }}</a></li>
18+
<li class="pull-right"><a class="btn btn-success" (click)="dealService.purchase(deal)">${{ deal.salePrice | number }}</a></li>
19+
</ul>
20+
</div>
21+
</div>
22+
</div>
23+
24+
<div class="col-sm-12">
25+
<div class="jumbotron text-center">
26+
<h2>View Public Deals</h2>
27+
<a class="btn btn-lg btn-success" routerLink="/deals">Public Deals</a>
28+
</div>
29+
</div>
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
2+
import { DealService } from '../deal.service';
3+
import { AuthService } from '../auth/auth.service';
4+
import { Subscription } from 'rxjs/Subscription';
5+
import { Deal } from '../deal';
26

37
@Component({
48
selector: 'app-private-deals',
59
templateUrl: './private-deals.component.html',
610
styleUrls: ['./private-deals.component.css']
711
})
8-
export class PrivateDealsComponent implements OnInit {
12+
export class PrivateDealsComponent implements OnInit, OnDestroy {
13+
dealsSub: Subscription;
14+
privateDeals: Deal[];
15+
error: any;
916

10-
constructor() { }
17+
constructor(public dealService: DealService) { }
1118

1219
ngOnInit() {
20+
this.dealsSub = this.dealService
21+
.getPrivateDeals()
22+
.subscribe(
23+
deals => this.privateDeals = deals,
24+
err => error => this.error = err
25+
);
26+
}
27+
28+
ngOnDestroy() {
29+
this.dealsSub.unsubscribe();
1330
}
1431

1532
}

ng2auth/src/app/public-deals/public-deals.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { DealService } from '../deal.service';
33
import { AuthService } from '../auth/auth.service';
44
import { Subscription } from 'rxjs/Subscription';
5-
import { Deal } from './../deal';
5+
import { Deal } from '../deal';
66

77
@Component({
88
selector: 'app-public-deals',
@@ -12,19 +12,19 @@ import { Deal } from './../deal';
1212
export class PublicDealsComponent implements OnInit, OnDestroy {
1313
dealsSub: Subscription;
1414
publicDeals: Deal[];
15+
error: any;
1516

1617
constructor(
17-
private dealService: DealService,
18+
public dealService: DealService,
1819
private authService: AuthService) { }
1920

2021
ngOnInit() {
21-
this.dealsSub = this.dealService.getPublicDeals().subscribe(
22-
deals => this.publicDeals = deals
23-
);
24-
}
25-
26-
purchase(item) {
27-
alert(`You bought the: ${item.name}`);
22+
this.dealsSub = this.dealService
23+
.getPublicDeals()
24+
.subscribe(
25+
deals => this.publicDeals = deals,
26+
err => this.error = err
27+
);
2828
}
2929

3030
ngOnDestroy() {

0 commit comments

Comments
 (0)