]>
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', | |
ec8d8440 C |
7 | templateUrl: './friend-list.component.html', |
8 | styleUrls: [ './friend-list.component.scss' ] | |
e2f555ca C |
9 | }) |
10 | export class FriendListComponent implements OnInit { | |
11 | friends: Friend[]; | |
12 | ||
13 | constructor(private friendService: FriendService) { } | |
14 | ||
15 | ngOnInit() { | |
93c462b7 | 16 | this.getFriends(); |
e2f555ca C |
17 | } |
18 | ||
e2f555ca C |
19 | quitFriends() { |
20 | if (!confirm('Are you sure?')) return; | |
21 | ||
22 | this.friendService.quitFriends().subscribe( | |
23 | status => { | |
24 | alert('Quit friends!'); | |
93c462b7 | 25 | this.getFriends(); |
e2f555ca | 26 | }, |
da4971c1 | 27 | error => alert(error.text) |
e2f555ca C |
28 | ); |
29 | } | |
93c462b7 C |
30 | |
31 | private getFriends() { | |
32 | this.friendService.getFriends().subscribe( | |
33 | friends => this.friends = friends, | |
34 | ||
da4971c1 | 35 | err => alert(err.text) |
93c462b7 C |
36 | ); |
37 | } | |
e2f555ca | 38 | } |