我用 Arduino 创建了一个项目,我通过 sub 和 pub 键将实时数据发送到 pubNub,这一切都很好。我并不是试图将数据从 PubNub 获取到我的 Angular5 应用程序中。
我已经订阅了该 channel ,如下所示:
constructor(pubnub: PubNubAngular) {
pubnub.init({
publishKey: 'My_pub_key',
subscribeKey: 'My_sub_key'
})
pubnub.subscribe({
channels: ['MyChannel'],
triggerEvents: true,
withPresence: true,
autoload: 100
});
}
这是一个名为“pubnub”的组件。然后,我执行此操作,将其发布到名为 arduino-app 的组件中的我的页面:
<div class="col-md-5 bgwhite" *ngIf="!appStart">
<h3 style="color: red; padding-top:1%;"> Application beginning...</h3>
<app-pubnub></app-pubnub>
</div>
但是数据没有发布到我的应用程序,以前有人对此做过什么吗?任何帮助都会很棒!
最佳答案
我相信您订阅后需要收到消息。
这就是我的工作方式:
pubnub.subscribe({channels: ['MyChannel'], triggerEvents: true, withPresence: true, autoload: 100});
this.threads = pubnub.getMessage('MyChannel')
然后我可以从线程
访问消息
另请查看https://github.com/pubnub/pubnub-angular2获取更多文档。
关于angular - 将 PubNub 链接到 Angular5 以在网络应用程序中发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49841941/