mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
add SignalR client service
This commit is contained in:
@@ -1,11 +1,37 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
import { FeedService, ConnectionState } from '../shared/feed.service';
|
||||
|
||||
@Component({
|
||||
selector: 'home',
|
||||
templateUrl: 'app/home/home.component.html'
|
||||
})
|
||||
export class HomeComponent implements OnInit {
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() { }
|
||||
error: any;
|
||||
|
||||
constructor(private service: FeedService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.service.connectionState
|
||||
.subscribe(
|
||||
connectionState => {
|
||||
if (connectionState == ConnectionState.Connected) {
|
||||
console.log('Connected!');
|
||||
} else {
|
||||
console.log(connectionState.toString());
|
||||
}
|
||||
},
|
||||
error => {
|
||||
this.error = error;
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
if (this.service.currentState === ConnectionState.Connected) {
|
||||
console.log(' connected....');
|
||||
}
|
||||
else {
|
||||
console.log('not connected');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user