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