Component had no action handler for… Behaviour changes between ember 2.8.0 and 2.8.1

旧时模样 提交于 2019-12-25 08:28:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!