@Component({
selector: 'my-friend-list',
- template: require('./friend-list.component.html'),
- styles: [ require('./friend-list.component.scss') ]
+ templateUrl: './friend-list.component.html',
+ styleUrls: [ './friend-list.component.scss' ]
})
export class FriendListComponent implements OnInit {
friends: Friend[];
constructor(private friendService: FriendService) { }
ngOnInit() {
- this.friendService.getFriends().subscribe(
- friends => this.friends = friends,
-
- err => alert(err)
- );
- }
-
- makeFriends() {
- this.friendService.makeFriends().subscribe(
- status => {
- if (status === 409) {
- alert('Already made friends!');
- } else {
- alert('Made friends!');
- }
- },
- error => alert(error)
- );
+ this.getFriends();
}
quitFriends() {
this.friendService.quitFriends().subscribe(
status => {
alert('Quit friends!');
+ this.getFriends();
},
- error => alert(error)
+ error => alert(error.text)
+ );
+ }
+
+ private getFriends() {
+ this.friendService.getFriends().subscribe(
+ friends => this.friends = friends,
+
+ err => alert(err.text)
);
}
}