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