How can I refresh/reload Polymer element, when page changes?

怎甘沉沦 提交于 2019-12-05 01:53:22

问题


I created few custom elements. When they get ready(triggered by ready()), they start downloading JSON data from API, and show to the users. Want to use them in Single Page Application, and to download data when it becomes visible. Right now, it downloads all the data of all the pages first, because I used ready() event.

Is it possible to fire an event every time they become visible?


回答1:


I found a solution. But, it's a little bit tricky. First, I added a function called isEqual.

app.isEqual = function(x, y) {
  return x === y;
};

And, used dom-if.

<section data-route="groups">
  <template is="dom-if" if="{{isEqual(route, 'groups')}}" restamp="true">
    <tend-groups-joined></tend-groups-joined>
  </template>
</section>

So, basically it compares the current route with a string parameter I pass, if it matches it restamps. A little bit tricky, but it worked.



来源:https://stackoverflow.com/questions/31482568/how-can-i-refresh-reload-polymer-element-when-page-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!