【发布时间】:2018-04-17 13:28:14
【问题描述】:
我正在尝试将 pubnub 历史记录发布到我正在构建的网络应用程序中。我目前只能将其发送到控制台。这就是我所拥有的:
pubnub.history(
{
channel: 'jChannel',
reverse: false, // false is the default
count: 100, // 100 is the default
stringifiedTimeToken: true // false is the default
},
function (status, response)
{
// LOG HISTORY TO CONSOLE
console.log("History Below: ")
console.log(response);
}
);
有谁知道我如何将它发布到我的网络应用程序上? 我试过这样做:
{{response}}
在我的 html 中,但这不起作用。任何帮助表示赞赏。
我的 ts:
export class ArduinoAppComponent implements OnInit {
public appStart = true;
public myMessage;
// CREATING MODEL FOR USER INPUT
model = {
firstname: "",
lastname: "",
}
constructor(pubnub: PubNubAngular) {
// LINKJ TO PUBNUB
pubnub.init({
publishKey: 'pub-',
subscribeKey: 'sub-'
})
pubnub.subscribe({
channels: ['jChannel'],
triggerEvents: true,
withPresence: true,
})
// CREATE PUBNUB HISTORY
pubnub.history(
{
channel: 'jChannel',
reverse: false, // false is the default
count: 100, // 100 is the default
stringifiedTimeToken: true // false is the default
},
function (status, response) {
// LOG HISTORY TO CONSOLE
console.log("History Below: ")
console.log(response);
}
);
和html:
<div class="col-md-3 minus-margin2">
<h2 style="padding-top: 75%;"> What's next?</h2>
<button class="btn btn-info">next?</button>
{{response}}
</div>
【问题讨论】:
-
你能发布你的 html 和你使用它的 .ts 类吗?
-
@Overmachine 完成
-
这应该可以通过在您的 Angular 应用程序中正确绑定来实现。您查看过PubNub Angular2 (should be compatible with Angular5) docs 中的所有内容吗?
-
PubNub 的某个人可能会发布更正式的答案,但请参阅我们工程师的这些示例:github.com/ManuelFernando/PubNub-Angular2-Demo-CLI
标签: angular typescript angular5 pubnub