Exploring the archives of PubNub within Angular5

I've been working on integrating PubNub history into my web app, but I'm currently only able to view it in the console. Here's what I have so far:

pubnub.history(
    {
        channel: 'jChannel',

        reverse: false,
        count: 100,
        stringifiedTimeToken: true
    },
    function (status, response)
    {
        // LOG HISTORY TO CONSOLE
        console.log("History Below: ")
        console.log(response);
    }
);

I'm struggling to figure out how to display this information on my web app. I've tried using the following code within my HTML:

{{response}}

Unfortunately, this method doesn't seem to work. Any guidance would be greatly appreciated.

My TypeScript file looks like this:

export class ArduinoAppComponent implements OnInit {
    public appStart = true;
    public myMessage;

    model = {
        firstname: "",
        lastname: "",
    }

    constructor(pubnub: PubNubAngular) {
        pubnub.init({
            publishKey: 'pub-',
            subscribeKey: 'sub-'
        })

        pubnub.subscribe({
            channels: ['jChannel'],
            triggerEvents: true,
            withPresence: true,
        })

        pubnub.history(
            {
                channel: 'jChannel',
                reverse: false,
                count: 100,
                stringifiedTimeToken: true
            },
            function (status, response) {
                console.log("History Below: ")
                console.log(response);
            }
        );

And here is a snippet from my HTML file:

<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>

Answer №1

To retain the historical response value, it is necessary to assign it to a variable.

export class ArduinoAppComponent implements OnInit {
public appStart = true;
public myMessage;
public history: any = {};
// DEFINING A MODEL FOR USER INPUT
 model = {
   firstname: "",
   lastname:"",
}


constructor(pubnub: PubNubAngular) {
  // LINK TO PUBNUB
  pubnub.init({
      publishKey: 'pub-',
      subscribeKey: 'sub-'
      })
      pubnub.subscribe({
        channels: ['jChannel'],
        triggerEvents: true,
        withPresence: true,

    })

    // RETRIEVE PUBNUB HISTORY
    pubnub.history(
    {
        channel: 'jChannel',

        reverse: false, // false by default
        count: 100, // default is 100
        stringifiedTimeToken: true // default is false
    }, function (status, response){
        //assign the response to the predefined variable.
        this.history = 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>
   <span>{{history}}</span>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to retrieve JSON data and present it in a grid layout

I have a JSON file with the following data: { "rooms":[ { "id": "1", "name": "living", "Description": "The living room", "backgroundpath":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrsU8tuZWySrSuRYdz7 ...

I'm having trouble with ViewChild - consider upgrading to beta7 for a solution

import {Page,NavController,NavParams,Platform,IonicApp} from 'ionic-angular'; import {ViewChild} from '@angular/core'; @Page({ templateUrl: 'build/pages/tabspage/tabspage.html' }) @ViewChild('myTabs') tabRef: T ...

Facing Syntax Errors When Running Ng Serve with Ngrx

Currently, I am enrolled in an Angular course to gain proficiency in ngrx. In a couple of months, I will be responsible for teaching it, so I am refreshing my memory on the concept. Strangely, even after installing it and ensuring my code is error-free, er ...

Storing data from a service into an array in Angular: Best practices

I have a service that provides getter and setter methods, returning id: number and title: String values from my dialog component. I am trying to save these responses into my data array but struggling to achieve it. For instance: 0: {id: 0, title: &qu ...

Exploring the benefits of useContext in Expo router

Currently, I am working with the latest Expo-Router version which incorporates file-based navigation. To establish a universal language context in my application, I have utilized React's context API along with the useReducer hook. However, I am encoun ...

Installing failed due to an error in the postinstall script of @angular/core version 9

I'm at the beginning of my coding journey and I am looking to set up a source code on my computer. node -v v12.16.1 npm -v 6.13.4 Could you assist me in resolving this issue that arises when I try to run the npm install command (on Windows 7 ...

Is Typescript familiar with the import -> require syntax, but unfamiliar with the require -> import syntax?

My code includes a simple file that utilizes the ES6 module loader: 1.ts import {foo} from "./2" foo('hello'); 2.ts function foo (a){console.log(a);}; export {foo} When the tsconfig is configured as follows: "module": "commonjs", We can o ...

The specified attribute "matListItemTitle" is invalid in this context

Having trouble incorporating a list from Angular Material into an Angular project. WebStorm is showing the error mentioned in the title above. I came across the problem here, but in this scenario, I am unable to use matListItemTitle as a dynamic parameter ...

Switch up a button counter

Is there a way to make the like count increment and decrement with the same button click? Currently, the code I have only increments the like count. How can I modify it to also allow for decrements after increments? <button (click)="toggleLike()"> ...

I prefer to have static modules generated on the home page rather than dynamic ones

As a newcomer to Angular, I am facing an issue with dynamic modules in my project. Currently, all modules are being generated when I run the project, but I only want to generate the login page module. Below is a screenshot and the code from the app.routing ...

Angular developers may encounter a dependency conflict while attempting to install ngx-cookie

I'm currently facing an issue while attempting to add the ngx-cookie package for utilizing the CookieService in my application. Unfortunately, I am encountering some dependency conflicts that look like the following: $ npm install ngx-cookie --save np ...

Error: Select dropdown placeholder malfunctioning

Even after trying numerous solutions from various forums, I am unable to make the placeholder display in my code. Maybe a fresh perspective can help spot what I might be missing. view image here I have experimented with using "" as the value, as ...

Exploring the integration of namespace with enums in TypeScript

In the angular project I am currently working on, we are utilizing typescript for development. One key aspect of our project is an enum that defines various statuses: export enum Status { ACTIVE = 'ACTIVE', DEACTIVE = 'DEACTIVE' } ...

Angular Binding issue - Unable to bind to 'ngModel' as it is not recognized as a valid property of 'input' element, despite the property being present

I have developed a component class like the one below and I am attempting to link the class fields to the template, but encountered the following error: ERROR in src/app/admin/projects/projects.component.html: 41:34 - error NG8002: Can't bind to &ap ...

Issue with retrieving properties in Angular template due to undefined values in HTML

As a newbie to Angular, I am dedicated to improving my skills in the framework. In my project, I am utilizing three essential files: a service (Studentservice.ts) that emits an observable through the ShowBeerDetails method, and then I subscribe to this ob ...

Having trouble with routerLink in your custom library while using Angular 4?

In my Angular 4 project, I have developed a custom sidebar library and integrated it into the main project. My current issue is that I want to provide the option for users to "open in new tab/window" from the browser's context menu without having the ...

Can you explain the significance of using curly braces in an import statement?

The TypeScript handbook has a section on Shorthand Ambient Modules, where an import statement is shown as: import x, {y} from "hot-new-module"; It doesn't explain why y is in curly braces in the above statement. If both x and y were inside the brace ...

Utilizing and transmitting contextual information to the tooltip component in ngx-bootstrap

I am currently working on integrating tooltips in ngx-bootstrap and trying to figure out how to pass data to the ng-template within the tooltip. The documentation mentions using [tooltipContext], but it doesn't seem to be functioning as expected. Belo ...

Transferring AgGrid context in a functional React component

I have been working on a component that utilizes AgGrid to display a table, with the data sourced from a Redux selector. My goal is to include a button within a cell in the table that triggers an action based on the specific row's data. However, I a ...

What is the best method for storing objects in Firebase in order to easily rearrange them at a later time?

My list looks something like this: {"ids": [ { "id1": { "name": "name1", "lastname": "lastname1" } }, { "id2": { "name": "name2", "lastname": "lastname2" } }, { "id3": { "name": "name3", "l ...