Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an instance of a controller in Ember.js?

I'm trying to access an instance of a controller that has been wired automatically using App.initialize();

I've tried the below but it returns a Class not an instance.

Ember.get('App.router.invitesController')

like image 200
Denzo Avatar asked Oct 27 '12 05:10

Denzo


People also ask

What does a controller do in Ember?

In Ember. js, controllers allow you to decorate your models with display logic. In general, your models will have properties that are saved to the server, while controllers will have properties that your app does not need to save to the server.

What is the prime task performed by controllers in Ember JS?

What are the prime tasks that are performed by controllers in Ember. js? Decorating the model which is returned by the route is a very essential task that needs to be performed in Ember.

What is a component in Ember?

Ember components are used to turn markup text and styles into reusable content. Components consist of two parts: a JavaScript component file that defines behavior, and its accompanying Handlebars template that defines the markup for the component's UI. Components must have at least one dash in their name.

Is Ember front end?

EmberJS is one of the most opinionated front-end frameworks out there.


1 Answers

I have a quick post about this exact subject on my Blog. It's a little big of a different method, but seems to work well for Ember.js RC1.

Check it out at: http://emersonlackey.com/article/emberjs-instance-of-controller-and-views

The basic idea is to do something like:

var myController = window.App.__container__.lookup('controller:Posts');
like image 53
Emerson Avatar answered Oct 21 '22 16:10

Emerson