ember.js - Invoking closure actions from a component's template -


i'm instantiating component , attaching closure actions (new in ember v1.13):

/app/templates/template.hbs

{{my-component key=val lookup=(action 'dolookup')}} 

/app/templates/components/my-component.hbs

{{input value=coolfield}} <button {{action 'lookup' coolfield}}>look up!</button> 

/app/controllers/my-controller.js

export default ember.controller.extend({   actions: {     dolookup(field) {       // work…     }   } }); 

i under impression wouldn't need define action on component in case wire things up. far looks required:

/app/components/my-component.js

export default ember.component.extend({   actions: {     lookup(field) {       this.attrs.lookup(field);     }   } }); 

am confused how use closure actions? seems wiring action in component work before (with regular actions).

i had same issue. here's @ least 1 way how closure actions can used avoid manually writing js code forward actions.

/app/templates/template.hbs

{{my-component key=val lookup=(action 'dolookup')}} 

/app/templates/components/my-component.hbs

{{input value=coolfield}} <button {{action (action 'lookup' coolfield)}}>look up!</button> 

/app/controllers/my-controller.js

export default ember.controller.extend({   actions: {     dolookup(field) {       console.log('looking cool field value', field);     }   } }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -