初始化EmberJs中的控制器状态:Route#setupController vs Controller #init

时间:2021-10-03 21:10:18

There appear to be two alternative ways to set the initial state of a controller in EmberJs:

似乎有两种方法可以在EmberJs中设置控制器的初始状态:

When is it appropriate to use one over the other? Are they equivalent?

何时使用一个而不是另一个?它们是等价的吗?

1 个解决方案

#1


8  

Generally speaking, Controller#init gets called only once when the (usually singleton) controller is created, while Route#setupController is called each time the route is entered.

一般来说,当创建(通常是单例)控制器时,Controller#init只被调用一次,而每次输入路径时都会调用Route#setupController。

Any model-related properties should be set from Route#setupController. Other default setup can be handled in Controller#init.

应该从Route#setupController设置任何与模型相关的属性。其他默认设置可以在Controller#init中处理。

In most Ember apps I have worked on, Route#setupController is used more often than Controller#init.

在我工作的大多数Ember应用程序中,Route#setupController比Controller#init使用得更频繁。

#1


8  

Generally speaking, Controller#init gets called only once when the (usually singleton) controller is created, while Route#setupController is called each time the route is entered.

一般来说,当创建(通常是单例)控制器时,Controller#init只被调用一次,而每次输入路径时都会调用Route#setupController。

Any model-related properties should be set from Route#setupController. Other default setup can be handled in Controller#init.

应该从Route#setupController设置任何与模型相关的属性。其他默认设置可以在Controller#init中处理。

In most Ember apps I have worked on, Route#setupController is used more often than Controller#init.

在我工作的大多数Ember应用程序中,Route#setupController比Controller#init使用得更频繁。