Let's say I have the following web component:
<link rel="import" href="my-dialog.htm"> <my-dialog id='mydialog1' heading="A Dialog">Lorem ipsum</my-dialog>
See here for more information: http://cbateman.com/blog/a-no-nonsense-guide-to-web-components-part-1-the-specs/
and here: http://www.revillweb.com/tutorials/web-component-tutorial/
However, in addition to attributes, sometimes I would like to initialize it with some object that has a bunch of properties, for example:
var obj = { heading: 'hello there', data1: 123, name: 'blabla' }; //^^ this can be any type of data.. think some kind of data model here, and maybe I get this model from the server.
Therefore, I cannot send the specified object to my html via attributes, because I can have many settings and / or I can get it at a later point from the server, so I need to do this in javascript.
So, what I was doing, I just took an object after creating it:
// initialize is a function I have inside my web component $('#mydialog1').get(0).initialize(obj);
^^ And this works, initialize (..) is a function inside my web component .. But:
Question # 1 I wonder if this is the right way to initialize the web component as it seems a bit messy.
Also, if there is one instance of the web component in the code:
$('body').append("<my-dialog id='bla'></my-dialog>"); $('#bla').get(0).initialize(obj);
Question # 2 Can I assume on the second line that 'bla' was created here with all its methods? (pretty funny, it works, but I thought it might be better to wait for some event or something that the component is ready)