What is the method for retrieving Polymer data that has been bound and incorporating it into a script?

My current setup involves utilizing the <firebase-document> element to retrieve data from Firebase. The data is then bound to {{poster}}, which allows me to access details of the poster object using its keys. For instance, {{poster.name}} displays the name of the poster. However, when attempting to use {{poster.name}} in a script by executing console.log(this.poster.name), an error displaying undefined occurs. How can I successfully access the bound data stored in {{poster}}?

Below is my HTML element:

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/plastr-poster/plastr-poster.html">
<link rel="import" href="../bower_components/polymerfire/firebase-document.html">
<link rel="import" href="../bower_components/app-metadata/app-metadata.html">
<link rel="import" href="shared-styles.html">

<dom-module id="my-details">
  <template>
    <style include="shared-styles">
      :host {
        display: block;
      }
    </style>

    <app-route
      route="{{route}}"
      pattern="/:poster_id"
      data="{{routeData}}"
      tail="{{subroute}}">
    </app-route>

    <firebase-document
      id="firebaseDoc"
      path="/posters/[[routeData.poster_id]]"
      data="{{poster}}">
    </firebase-document>
    <app-metadata></app-metadata>

    <div class="poster_board">
      <a href="./[[routeData.poster_id]]">
        <plastr-poster id="poster" name="[[poster.name]]" location=[[poster.location]] poster="[[poster.poster]]" date="[[poster.date]]"></plastr-poster>
      </a>
    </div>
  </template>

  <script>
    Polymer({
      is: 'my-details',
      ready: function() {
        this.fire('app-metadata', {
          title: this.poster.name,
          description: "things to do in your 'hood",
          keywords: 'events, posters, local, music, dance, art'
        });
        console.log(this.poster.name);
      },
      attached: function() {
        // This line will create the singleton element if it hasn't been created yet
        Polymer.AppMetadata.requestAvailability();
      },
      properties: {
        prop1: {
          type: String,
          value: 'plastr-app',
        },
      }
  });

  </script>
</dom-module>

Answer №1

It appears that the ready handler in your code is attempting to access this.poster.name. However, it's important to note that at this point, this.poster may not have been populated yet by the <firebase-document>. To address this issue, consider using an observer on poster.name as shown below:

Polymer({
  // ...

  observers: ['_updateTitle(poster.name)'],

  _updateTitle: function(posterName) {
    if (posterName) {
      this.fire('app-metadata', {
        title: posterName,
        // ...
      });
    }
  }
);

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

Issue with the useSWR hook causing the DOM not to update correctly due to mutation

My next.js app is utilizing the `useSWR` hook to fetch and populate data. const { data, error } = useSWR('/api/digest', fetcher, { revalidateOnFocus: false, }) The problem I am facing is that the DOM is not updating as expected after the `mu ...

At what point is a $.cache considered oversized?

After coming across a fascinating tutorial, I learned that certain memory leaks in jQuery can be identified by monitoring the size of the $.cache variable. It was emphasized to always keep an eye on its size, as it could indicate potential issues if it bec ...

How can an Embedded React + JSS component safeguard generic elements such as <button> and <p> from being affected by the page's style?

I am facing a challenge with a React component that is being embedded in various webpages, either through an extension or as a third-party tool. Most of the styling for this component is done using JSS, ensuring unique class names that cannot be overridde ...

Element cannot be located following the addition of a className in the HTML document

When manually adding id, test-id or classname in an HTML file, it's important to note that Cypress may have trouble finding the element. For example, I have included 'Classname' here just for demonstration purposes. https://i.stack.imgur.co ...

Retrieve the highest 10 values from a JSON document using jQuery

I am working with a JSON file in my jQuery project, and I need to display only the top 10 values with the highest numbers. For instance: JSON: { "value": { "number": "12", "number": "11", "number": "10", "number": "9", "number": "8", ...

Display the input field value using ReactJs

Is there a way to immediately show the value of my input in the render function? While exploring the state and lifecycle concept in a React component, I came across the usage of a constructor with super(props) and this.state. However, when I attempted to ...

The expected result is not obtained when making an Ajax request to a PHP variable

I recently encountered an issue with my AJAX GET request. The response I received was unexpected as the PHP variable appeared to be empty. Here is the snippet of jQuery code that I used: jQuery(document).ready(function($) { $.ajax({ url: '/wp ...

Refresh the vue-owl-carousel following a dynamic data update

Utilized vue-owl-carousel with dynamic content <script> import carousel from 'vue-owl-carousel' export default { components: { carousel }, } <carousel :items="1"> <img v-for="(img, index) in images" ...

Conditionally Add Columns to jQuery Datatables

I am working with a jQuery datatable to showcase data retrieved through an AJAX request. However, I am interested in adding a third column to the table specifically for administrators, allowing them to delete entries. Can someone guide me on how to incorpo ...

The 'file' property of undefined throws an error in ng-file-upload

I am currently exploring the functionality of ng-file-upload from this repository: https://github.com/danialfarid/ng-file-upload I have successfully implemented the basic setup as follows: HTML: <section ng-controller="MyController"> ...

Showing a restricted number of rows in the JSP page

<table class="grid_alt" cellspacing="0" rules="all" border="1" id="id1" style="width:720px;border-collapse:collapse;"> <tbody> <tr align="left"> <th scope="col"><%=partner %></th><th scope="col"><%=item %>< ...

How can I transfer information from an HTML file (using the ejs template engine) to Node.js?

Currently, I am working on my own project using a combination of Node.Js (Express), MongoDB, JavaScript/jQuery, and HTML with EJS as the template engine. So far, I have some understanding of how to send data from the Node.js router to views and how to sen ...

Ways to implement a custom scrollbar across an entire webpage:

I am trying to implement the Jquery custom content scroller on my webpage to replace the default scrollbar. However, I am facing difficulties in getting it to work properly. You can view my code on Codepen. Although the plugin works fine with smaller blo ...

Asserting types for promises with more than one possible return value

Struggling with type assertions when dealing with multiple promise return types? Check out this simplified code snippet: interface SimpleResponseType { key1: string }; interface SimpleResponseType2 { property1: string property2: number }; inter ...

adding a JavaScript module to a handlebars template

I have a few different files that I'm working with: In the server.js file, I have the following code: app.get('/main/:id', function(req, res) { res.render('main', { products: products }); }) Within the main.hbs file, I have ...

Despite being invoked five times and enclosed in a React.Fragment tag, the functional component is still not displaying any content

<html lang="en"> <head> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js& ...

Fetching JSON data from an external URL using AngularJS

Check out this URL that shows JSON data in the browser: I attempted to store the data in a variable with the following code: $http.get('http://api.geosvc.com/rest/US/84606/nearby?apikey=4ff687893a7b468cb520b3c4e967c4da&d=20&pt=PostalCode& ...

Tips for adding a new property to an array object in TypeScript using a condition

Here is an array object that I have: arr = [ { Name: "ABC", Age: 20}, { Name: "XXX", Age: 15} ]; In Typescript, I am looking to dynamically add a new property called "Flag" with a value of 1 only if the Age is greater than 15. Can someone suggest ...

tips for transitioning between various json entities

Recently, I created a login page code using JavaScript that runs on a Node Express.js server. Users can input their username/email and password, and all the data gets stored in a JSON file structured like this: {"username":"admin"," ...

It appears that the pixel sizes are different than what was originally designed

In my project, I have a header panel where the burger button is designed with a width of 32px and height of 24px. .header { display: flex; font-weight: bold; font-size: 50px; height: 100px; border: 1px solid black; position: relativ ...