Ad

Polymer Register All Elements After My Custom Function

- 1 answer

I have js file with this

var global_actions ={};
$(document).ready(function () {

   myajaxcall(function(response){global_actions=response});

});

I have an elements with template :

 <template>
 ...
<h1>{{global_actions.greetingtext}}</h1>
...
</template>

The problem is that template draw and init before global_actions=myajaxresponse; What do i want 1.Call ajax and fill global_actions 2.Draw elements with databinding to global_actions data; What i got elements draw before myahaxcall(callback);

Ad

Answer

First of all For ajax you can use the ajax component https://elements.polymer-project.org/elements/iron-ajax

Second let say you use dom-bind and the custom element that you want to put is on the main

 var global_actions ={};
 $(document).ready(function () {
     myajaxcall(function(response){
     //use app or this
     app.isFinish = true; 
     app.response});
 });

in the html write

<template is="dom-if" if="[[isFinish]]">
   <custom-element some-data={{app.greetingtext}}></custom-element>
</template>

thus your element only render when you receive the response from server.

Ad
source: stackoverflow.com
Ad