Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run action in Ember Controller afterRender

I am new to ember framework. I just want to execute a function that is defined inside the actions hook after the rendering completes.

var Controller = Ember.Controller.extend({
  actions: {
    foo: function() {
        console.log("foo");
    }
  }
});
Ember.run.schedule("afterRender",this,function() {
  this.send("foo");
}

But the above code is not working. I just want to know, is it possible to run foo() afterRender?

like image 836
Mohan Kumar Avatar asked Jun 17 '15 06:06

Mohan Kumar


People also ask

What is action in Ember?

By default, the {{action}} helper listens for click events and triggers the action when the user clicks on the element. You can specify an alternative event by using the on option. <p> <button {{action "select" post on="mouseUp"}}>✓</button> {{post.

What is an ember controller?

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.


1 Answers

You could use init:

App.Controller = Ember.Controller.extend({
  init: function () {
    this._super();
    Ember.run.schedule("afterRender",this,function() {
      this.send("foo");
    });
  },

  actions: {
    foo: function() {
      console.log("foo");
    }
  }
});
like image 200
artych Avatar answered Oct 08 '22 01:10

artych