Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fire component's actions from template inserted in block-form component Ember.js?

Tags:

ember.js

I wanna fire component's actions from template inserted in block-form component like this:

{{#block-component}}
   <p> HTML inserted in block form </p>
   <p> How trigger a action from block-component (not your parent) from this scope? </p>
   <p {{action 'actionFromBlockComponent'}}> Fire component's action!!! </p>
{{/block-component}}

The block params enabled in Ember 1.10.0 can help me with this? Or this demand is impossible?

like image 502
user2838942 Avatar asked Feb 13 '15 18:02

user2838942


1 Answers

With the new block params in 1.10.0 this is possible by doing the following:

{{#block-component as |component|}}
    <p> HTML inserted in block form </p>
    <p> How trigger a action from block-component (not your parent) from this scope? </p>
    <p {{action 'actionFromBlockComponent' target=component}}> Fire component's action!!! </p>
{{/block-component}}

Note the target of the action set to the block param.

The template of the block-component should contain this:

{{ yield this }}

It simply passes the component itself to be used as a block param for any template using this component.

like image 129
jcbvm Avatar answered Oct 14 '22 06:10

jcbvm