added data service

This commit is contained in:
chsakell
2016-09-29 15:50:28 +03:00
parent e6aed79fa9
commit ac613432aa
6 changed files with 158 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FeedService } from '../shared/feed.service';
import { Match } from '../shared/interfaces';
import { DataService } from '../shared/data.service';
import { ConnectionState } from '../shared/interfaces';
@Component({
@@ -9,16 +11,21 @@ import { ConnectionState } from '../shared/interfaces';
})
export class HomeComponent implements OnInit {
matches: Match[];
error: any;
constructor(private service: FeedService) { }
constructor(private dataService: DataService,
private feedService: FeedService) { }
ngOnInit() {
this.service.connectionState
let self = this;
self.feedService.connectionState
.subscribe(
connectionState => {
if (connectionState == ConnectionState.Connected) {
console.log('Connected!');
self.loadMatches();
} else {
console.log(connectionState.toString());
}
@@ -27,12 +34,17 @@ export class HomeComponent implements OnInit {
this.error = error;
console.log(error);
});
}
if (this.service.currentState === ConnectionState.Connected) {
console.log(' connected....');
}
else {
console.log('not connected');
}
loadMatches(): void {
let self = this;
this.dataService.getMatches()
.subscribe((res: Match[]) => {
self.matches = res;
console.log(self.matches);
},
error => {
console.log(error);
});
}
}