5

Rendering a component works well when using {{component-name}} in template. I want to render a component from route with dynamic parameters. I've tried this

App.ApplicationRoute = Ember.Route.extend({
  init: function(){
      this.render("components/comp-two", {
        into: "application",
        outlet: "test"
      });

  }
});

It successfully renders a template, but component's events(init, didInsertElement) and actions don't work.

How to make events and actions work ?

example: http://emberjs.jsbin.com/badaku/1/

Tomas
  • 1,377
  • 3
  • 17
  • 32
  • Try with writing this code in renderTemplate method. – Vaibhav Mar 16 '15 at 08:29
  • @Vaibhav doesn't seem to work if I replace the method to renderTemplate. It alerts the temp-one twice, but doesn't render anything. Could you supply an example in jsbin by editing mine ? – Tomas Mar 16 '15 at 08:47
  • Actually here in route, if you define, then only template gets rendered, it is not considered as a component. You can create a dummy template, inside that you can use your component. – Vaibhav Mar 16 '15 at 08:58

1 Answers1

3

If you give some template name in render method, ember only will render that specific template, it will not be considered as a component.You can create a dummy template, inside that you can use your component.

I have updated your jsBin example http://jsbin.com/pajirefeta/1/edit

Vaibhav
  • 1,479
  • 8
  • 13
  • The thing is I want to pass dynamic parameters like {{comp-print "thisText"}} and `thisText` is downloaded from server and can't be hardcoded in template – Tomas Mar 16 '15 at 09:36
  • you want to pass some argument to your component? – Vaibhav Mar 16 '15 at 09:42
  • Yes. I'm building a modal component which will be rendered into an outlet. – Tomas Mar 16 '15 at 10:04
  • 2
    then you can pass data as {{comp-one compData="thisText"}} and use compData property inside component. – Vaibhav Mar 16 '15 at 10:07
  • `thisText` is downloaded from server, and can't be hardcoded in a template :) – Tomas Mar 16 '15 at 10:13
  • 2
    You can have a property for example myProp, which will get the dynamic data(myProp = thisText) and you can assign this to component {{comp-one compData=myProp}} Here nothing is hard coded, you dynamic property can also be used. Remember, not to put quotes on your property, in that case it will be a string. – Vaibhav Mar 16 '15 at 10:16
  • Yeah, that's possible, but doesn't feel right. Still thanks for solutions ;) – Tomas Mar 16 '15 at 11:05
  • maybe it doesn't feel right and the Ember Team will add the option to render a component from route, but right now Vaibhav's solution is the right one. Same in here: http://stackoverflow.com/questions/21683320/render-view-component-with-parameters-into-named-outlet-ember-js – licancabur Mar 17 '15 at 11:10