ember.js - Obtaining component elementId in parent template -


i obtain component auto-generated elementid in parent template, e.g.

<script type="text/x-handlebars" data-template-name="index">   my-component elementid: {{mycomponentelementid}}   {{my-component}} </script> 

is there simple way without altering parent controller or my-component?

elementid being generated during initialization of component. can sure id set after component inserted dom. therefore, can use didinsertelement action this:

some-example elementid: {{mycomponentelementid}} {{some-example elementidproxy=mycomponentelementid}}  didinsertelement: function() {   this.set("elementidproxy", this.get("elementid")); } 

thus, proxy elementid via other binding (elementidproxy in situation). recommend not set id explicitly, must unique within app. ember takes care that, it's not idea reinvent wheel.

fully working example in jsbin here


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -