2016-05-20 41 views
2

當可路由組件未來即將到來時,我一直在期待控制器的結束。所以我一直把我的行動處理程序放在我的路線上。Ember 2.5中的操作 - 路由還是控制器?

// app/something/route.js 
actions: { 
    doSomething() { 
     alert('action handled in route'); 
    } 
} 

在我的模板:

{{!-- app/something/template.hbs --}} 
{{some-component action="doSomething"}} 

在我的組件:

{{!-- app/components/some-component/template.hbs --}} 
<button {{action "onClickButton"}}>Click Me</button> 

// app/components/some-component/component.js 
actions: { 
    onClickButton() { 
     this.sendAction(); 
    } 
} 

我應該處理的路線行動,避免控制器完全?

+1

不,你不應該避免控制器。這是適得其反並且不必要的。 – locks

+0

好,但我看到相反的建議http://emberigniter.com/should-we-use-controllers-ember-2.0/但沒有很多方向。請注意指向我缺少的一些文檔? –

+1

https://locks.svbtle.com/controllers-are-dead-long-life-controllers https://guides.emberjs.com/v2.5.0/controllers/ – locks

回答

2

看來,控制器對T要走了,多虧輸入從@locks他是Ember學習團隊。

根據his blog post

作爲面向未來的從未使用任何控制器從不意思。

產生的所有路由控制器。

您甚至可以在git committrek看到Ember團隊正在軟化他們在控制器上的立場。

因此,最後,控制器可以很好地使用。這就是我要採取行動的地方。

相關問題