javascript - How to dynamically create a polymer element -


i trying create paper-toast element javascript using

var toast = document.createelement('paper-toast'); 

that creates element , add body after setting attributes.

document.body.appendchild(toast); 

this works, element shows in devtools. then, when try call

toast.show(); 

even when deferred (using settimeout(1)) errors undefined not function, due newly created element not having function properties should according documentation.

how can use show method of element? not have created dynamically, need able change content , seemed easy solution.

be sure import element definition html import.

<link rel="import" href="components/paper-toast/paper-toast.html"> 

when have lot of custom elements, can hard tell ones missing imports. can use bookmarklet detect missing imports

https://gist.github.com/ebidel/cea24a0c4fdcda8f8af2

javascript:(function()%7bfunction%20isunregisteredcustomelement(el)%7bif(el.constructor==htmlelement)%7bconsole.error('found%20unregistered%20custom%20element:',el);return%20true;%7dreturn%20false;%7dfunction%20iscustomel(el)%7breturn%20el.localname.indexof('-')!=-1%7c%7cel.getattribute('is');%7dvar%20allcustomelements=document.queryselectorall('html%20/deep/%20*');allcustomelements=array.prototype.slice.call(allcustomelements).filter(function(el)%7breturn%20iscustomel(el);%7d);var%20foundsome=false;for(var%20i=0,el;el=allcustomelements[i];++i)%7bif(isunregisteredcustomelement(el))%7bfoundsome=true;%7d%7dif(foundsome)%7balert('oops:%20found%20one%20or%20more%20unregistered%20custom%20elements%20in%20use!%20check%20the%20console.');%7delse%7balert('good:%20all%20custom%20elements%20are%20registered%20:)');%7d%7d)(); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -