mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
added data service
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user