windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

How to get element in dom-if or dom-repeat?

Asked By: Anonymous
<dom-module id="weather-data">
<template>
  <style is="custom-style" include="iron-flex iron-flex-alignment">


 :host {
      display: block;
      font-family: Roboto;
    }

    paper-progress {
      top: 0;
      left: 0;
      position: fixed;
      width: 100%;
      --paper-progress-active-color: var(--paper-light-blue-500);
      --paper-progress-secondary-color: var(--paper-light-blue-100);
    }

    paper-icon-button {
      margin: 0 auto;
      margin-top: 20px;
      display: block;
    }

    #weatherIcon {
      width: 200px;
      height: 200px;
    }

    table {
      border-collapse: collapse;
    }

    table td {
      text-align: center;
      border: 1px solid #006064;
      padding: 5px;
    }

  </style>

  <paper-progress
    id="request-progress"
    indeterminate
    hidden$="[[!activeRequest]]">
  </paper-progress>

  <iron-ajax
    id="getData"
    auto
    url="[[weatherApiUrl]]"
    handle-as="json"
    last-response="{{weatherResponse}}"
    last-error="{{error}}"
    params="[[_getGegevensVanLocatie(coordinaten.latitude,        coordinaten.longitude)]]"
    loading="{{activeRequest}}">
  </iron-ajax>

  <template is="dom-if" id="tmp" if="[[weatherResponse]]">
    <paper-icon-button
    id="location-button"
    disabled$="{{disableLocationButton}}"
    on-tap="_getLocation"
    icon="maps:my-location"
    alt="Zoek mijn huidige locatie">
    </paper-icon-button>

    <div>
      <div class="horizontal center-justified layout">
        <h2>Weer voor locatie: <span>[[_maakLocationString(weatherResponse.query.results.channel.location)]]</span></h2>
      </div>
      <div class="horizontal center-justified layout">

        <iron-icon
          id="weatherIcon"
          icon="[[_getIcon(weatherResponse.query.results.channel.item.condition.code)]]">
        </iron-icon>

      </div>
      <div class="horizontal center-justified layout">
        <h2>
          <span>
            [[weatherResponse.query.results.channel.item.condition.text]],
            [[weatherResponse.query.results.channel.item.condition.temp]]° [[weatherResponse.query.results.channel.units.temperature]]
          </span>
        </h2>
      </div>
      <div class="horizontal center-justified layout">
        <table>
          <tr>
            <td>
              <iron-icon icon="icons:arrow-upward"></iron-icon>
            </td>
            <td>
              <iron-icon icon="icons:arrow-downward"></iron-icon>
            </td>
          </tr>
          <tr>
            <td>[[weatherResponse.query.results.channel.astronomy.sunrise]]</td>
            <td>[[weatherResponse.query.results.channel.astronomy.sunset]]</td>
          </tr>
        </table>
      </div>
      <div class="horizontal center-justified layout">
        <h5 id="update-time">
          Gegevens geraadpleegd om: [[weatherResponse.query.results.channel.item.condition.date]]<span></span>
        </h5>
      </div>
    </div>
  </template>
</template>

<script>


    Polymer({
        is: 'weather-data',
        properties: {
            weatherApiUrl: {
                type: String,
                value: "https://query.yahooapis.com/v1/public/yql"
            },
            coordinaten: {
                type: Array,
                value: {
                    longitude: 22,
                    latitude: 22
                }
            }
        },
        ready: function() {
            if (navigator.permissions && navigator.permissions.query) {
                navigator.permissions.query({
                    name: 'geolocation'
                }).then(function(status) {
                    if (status.state === 'granted') {
                        console.log("Permisson already granted");
                        _getLocation();
                    } else {
                        console.log("Location not YET granted, using default coordinates");
                        if (status.state === "denied") {
                            console.log("Denied");
                        }
                    }
                });
            } else {
                console.log("Permission not available");
                console.log("Using standard coordinates");
            }
        },
        _getLocation: function() {
            console.log("Getting location");
        },
        _getGegevensVanLocatie: function(latitude, longitude) {
            var latLong = '(' + 51.0339 + ',' + 3.7094 + ')';
            return {
                format: 'json',
                q: 'select * from weather.forecast where woeid in ' +
                    '(select woeid from geo.places(1) where text="' + latLong + '") and u="c"'
            };
        },
        _maakLocationString: function(location) {
            if (location.city && location.region) {
                return location.city + ', ' + location.region;
            } else {
                return location.city || 'Onbekend';
            }
        },
        _getIcon: function(code) {
            if (code >= 37 || code <= 12) {
                return "image:flash-on";
            }

            if (code <= 18) {
                return "image:flare";
            }

            if (code <= 30) {
                return "image:wb-cloudy";
            }

            return "image:wb-sunny";
        }
    })
</script>

So this is my code. What I’m trying to do is get the <paper-icon-button> element when the permission is granted on the navigator when the state is changed to granted. However this does not work with this.$.location-button or with this.$$('#location-button).

Is this because I use it in the ready() function?


Solution

Answered By: Anonymous

The dom-if template stamps its contents into the DOM only when its if property becomes truthy. Once the content has been stamped it only hides and shows the content when the if property changes. Though setting restamp to true destroys and creates the content anew.

Therefore you cannot locate your paper-icon-button before you have fetched your weatherResponse which it has not done in your element ready lifecycle callback.

Note that in the docs for polymers conditional templates usage it says:

Since it is generally much faster to hide and show elements rather than destroy and recreate them, conditional templates are only useful to save initial creation cost when the elements being stamped are relatively heavyweight and the conditional may rarely (or never) be true in given usages. Otherwise, liberal use of conditional templates can actually add significant runtime performance overhead.

So perhaps changing your dom-if template into a element (e.g. div) with a hidden$="[[!weatherResponse]]" attribute would be more appropriate in your case. This would also have the paper-icon-button be stamped when ready is called.

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
Alanya escort Manavgat escort Fethiye escort Kemer escort Didim escort http://www.kadinescort.net Gaziantep escort Denizli escort Adana escort Hatay escort Aydın escort İzmir escort Ankara escort Antalya escort Bursa escort İstanbul escort Kocaeli escort Konya escort Muğla escort Malatya escort Kayseri escort Mersin escort Samsun escort Sinop escort Tekirdağ escort Eskişehir escort Yalova escort Rize escort Amasya escort Balıkesir escort Çanakkale escort Bolu escort Erzincan escort Şırnak escort Van escort Yozgat escort Zonguldak escort Afyon escort Adıyaman escort Bilecik escort Aksaray escort Ağri escort Bitlis escort Siirt escort Çorum escort Burdur escort Diyarbakir escort Edirne escort Düzce escort Erzurum escort Kırklareli escort Giresun escort Kilis escort Kars escort Karabük escort Kırıkkale escort Mardin escort Kırşehir escort Maraş escort Manisa escort Muş escort Kastamonu escort Ordu escort Nevşehir escort Sakarya escort Osmaniye escort Şanliurfa escort Sivas escort Trabzon escort Tokat escort Ardahan escort Bartın escort Karaman escort Batman escort Bayburt escort Bingöl escort Elaziğ escort Gümüşhane escort Hakkari escort Isparta escort Uşak escort Igdır escort