Hardik127
Hardik127

Reputation: 344

why emberjs creates all controllers on Application initialization?

On application initialization , all the controllers are initialized by Ember. After working with any of the controllers, it retains its values, that becomes a problem while reusing the controller. I would wanna know :

  1. the benefit of initializing all controller at application initialization?
  2. Is there any way to solve my problem of reusing controllers such that all the variables are reset ?

PS : Please don't misunderstand "reusing controllers". All I want is to use the same controller without the previously entered values from any previous task.

Upvotes: 0

Views: 399

Answers (1)

Luke Melia
Luke Melia

Reputation: 8389

Controllers are intended to be long-lived and hold application state even as their views may blink in and out of existence. In a typical Ember app, controllers are created once and live for the life of the app, hence the reasoning for initializing them all at app initialization time.

For an easy way to "reset" a controller, you could use an Ember.ObjectController, that proxies gets and sets of properties not defined on the controller the object you set as the content property. To reset the controller, just set content to a fresh object.

Upvotes: 2

Related Questions