import { Component, OnInit } from '@angular/core';
-import { ROUTER_DIRECTIVES } from '@angular/router';
import { Friend, FriendService } from '../shared';
@Component({
selector: 'my-friend-list',
- template: require('./friend-list.component.html'),
- styles: [ require('./friend-list.component.scss') ],
- directives: [ ROUTER_DIRECTIVES ]
+ 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)
- );
+ 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)
);
}
}