我使用import * as signalR from "@aspnet/signalr";
并使用toastr
在ngOnInit
内部,我从套接字监听数据:
connection.on("receivePassportData", data => {
console.log(data);
this.toastr.error('Title', 'Already checked!');
});
因此,我每次看到console.log(data)
都有数据,但是当我打电话给吐司时却不显示消息。
如果通过单击DOM元素调用Toast,则效果很好。
我可以使用AnyDesck演示问题
完整代码是:
public run() {
this.toastr.success('aadadasd', 'Already checked!'); // It works immidiatly
}
ngOnInit() {
let session = sessionStorage.getItem("credentials");
if (session) {
let _session = JSON.parse(session);
this.userId = _session.user.id;
}
connection = new signalR.HubConnectionBuilder()
.configureLogging(signalR.LogLevel.Debug)
.withUrl("http://localhost:8002/dataHub")
.build();
//connection.serverTimeoutInMilliseconds = 100000;
connection
.start()
.then(() => {
console.log("Connected!");
//let a = this.toastr;
connection
.invoke("join", this.userId)
.then(() => {
// console.log("joined to channel");
})
.catch(err => console.error(err.toString()));
})
.catch(function (err) {
return console.error(err.toString());
});
connection
.on("receivePassportData", data => {
//a.error('', 'Checked');
this.toastr.error('aadadasd', 'Already checked!');
//this.scanDo(data);
});
connection
.on("receiveQRData", data => {
this.toastr.error('aadadasd', 'Already checked!');
});
connection.onclose(error => {
console.log(error);
});
}
未显示部分代码烤面包机:
connection.on("receiveQRData", data => {this.toastr.error('aadadasd', 'Already checked!');
});