如何从父级调用 child(`component`) 方法?

How to call child(`component`) method from parent?

如何从父(路由器)模板调用子(组件)方法?

我想知道 ember 推荐的正确方法。

这是我的尝试(我直接调用不行!!)

Live demo on Twiddle

因为ember座右铭是Data down, Action up。从子组件调用动作没有意义。

但如果它适合您的情况,请将其用作 contextual。如图所示this twiddle.

如:

{{#child-omponent as |actionHandler|}}

  <footer>
    <h3 onclick={{action actionHandler }}>Click me to called child components action</h3>
  </footer>

{{/child-omponent}}