Сообщение от SignalR идет.Я хочу отправить уведомление пользователю после получения message.but из сообщения функции undefined. В чем причина.
console.log ("abc", mes) -> сообщение отображается в консоли.console.log ("cba", mes) -> сообщение не отображается в console.result -> cba undefined
home-page.ts
import { Component,EventEmitter } from '@angular/core';
import { hubConnection } from 'signalr-no-jquery';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { AlertController,NavController } from '@ionic/angular';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private localNotifications: LocalNotifications,public alertCtrl:
AlertController,public navCtrl: NavController) {
}
ngOnInit() {
let mes :string;
const connection = hubConnection('http://domain.tk/');
const hubProxy = connection.createHubProxy('signalrserver');
connection.start()
.done(function(){
console.log('Now connected, connection ID=' + connection.id);
hubProxy.invoke('sendMessages');
})
.fail(function(){ console.log('Could not connect'); });
hubProxy.on('sendMessages', function(message) {
mes = message;
console.log("abc", mes);
});
console.log("cba", mes);
this.localNotifications.schedule({
id: 1,
text: mes
});
}
}