0

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

  • your question is not clear.what do you mean with init? – Alon Feb 02 '16 at 00:06
  • So put this in template if.. I dont understand why you cant in the ajax change the value of this.myproperty?? – Alon Feb 02 '16 at 11:37
  • because i have 10 elements and i will not call the same function on all elements. i have one function that fill data for all elements in one global object. after its filled all elements read this object in ELEMENT.ready function. – Sergiy Tokarchuk Feb 02 '16 at 13:23
  • sorry, but I dont understand your question, if you want to insert the element after the ajax you can use the template-if , or you can let the binding system work, and show your content after you receive the ajax response. – Alon Feb 02 '16 at 13:27
  • Thanks #Alon i found a solution Global variables :) http://stackoverflow.com/questions/24867741/polymer-global-variables – Sergiy Tokarchuk Feb 02 '16 at 14:53

1 Answers1

0

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.

Alon
  • 2,919
  • 6
  • 27
  • 47