]>
Commit | Line | Data |
---|---|---|
e2f555ca C |
1 | import { Component, OnInit } from '@angular/core'; |
2 | ||
3 | import { Friend, FriendService } from '../shared'; | |
4 | ||
5 | @Component({ | |
6 | selector: 'my-friend-list', | |
7 | template: require('./friend-list.component.html'), | |
8 | styles: [ require('./friend-list.component.scss') ] | |
9 | }) | |
10 | export class FriendListComponent implements OnInit { | |
11 | friends: Friend[]; | |
12 | ||
13 | constructor(private friendService: FriendService) { } | |
14 | ||
15 | ngOnInit() { | |
16 | this.friendService.getFriends().subscribe( | |
17 | friends => this.friends = friends, | |
18 | ||
19 | err => alert(err) | |
20 | ); | |
21 | } | |
22 | ||
23 | makeFriends() { | |
24 | this.friendService.makeFriends().subscribe( | |
25 | status => { | |
26 | if (status === 409) { | |
27 | alert('Already made friends!'); | |
28 | } else { | |
29 | alert('Made friends!'); | |
30 | } | |
31 | }, | |
32 | error => alert(error) | |
33 | ); | |
34 | } | |
35 | ||
36 | quitFriends() { | |
37 | if (!confirm('Are you sure?')) return; | |
38 | ||
39 | this.friendService.quitFriends().subscribe( | |
40 | status => { | |
41 | alert('Quit friends!'); | |
42 | }, | |
43 | error => alert(error) | |
44 | ); | |
45 | } | |
46 | } |