问题
Please see this ember-twiddle.
What I want is to provide custom buttons with custom actions to a component. The component itself does not know about the actions involved, these actions are expected to bubble to the corresponding controller.
This code works in ember 2.8.0 but not in the current release version (2.8.2). Please use the twiddle to change between emberjs "2.8.0" and "release". Is this an emberjs bug?
回答1:
Yes it's Bug in ember version 2.8.0 alone. this has been fixed in next version 2.8.1. Related link : https://github.com/emberjs/ember.js/pull/14291/files
For your use case, I created twiddle
Have actions in application controller,
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions:{
buttonMethod(){
console.log('buttonMethod');
}
}
});
Create my-button component so that it can be included in any of the component. this will call closure action which is passed from parent component.
In my-button.hbs
<button {{action buttonMethod }}> ButtonComponent </button>
{{yield}}
create my-component
component and send closue action buttonMethod to my-button
component.
In my-component.hbs
{{my-button buttonMethod=buttonMethod }}
{{yield}}
In application.hbs
, this is place we are creating closure action to buttonMethod
action in controller. so we need to pass this buttonMethod
property all the way down to button component.
{{my-component buttonMethod=(action 'buttonMethod') }}
来源:https://stackoverflow.com/questions/40081014/component-had-no-action-handler-for-behaviour-changes-between-ember-2-8-0-and