Ember Calling method inside the controller

59 views Asked by At

here is my code I have to call another method inside the Ember controller I was tried but this is not working I have confused in this...

please help me to what is wrong in this code?

export default Ember.Controller.extend({
  ....

  getValue(){
    var a = 7 * 2;
    return a;
  },

  getResult(){
    var result = this.getValue(); // result is this.getValue is not function 
  }
});
2

There are 2 answers

5
Lux On

First this code does not makes sense:

getValue(){
  var a = a * 2;
  return a;
},

here you're using a before you declare it.


but to answer your question: your code is correct.

Here is a working example. I've just replaced var a = a * 2; by var a = 7 * 2; to make this code valid.

1
Paul On

My assumption is that whatever is calling getResult() is not setting the context of this to the controller, and my hunch is that you'll need to put getResults() in the actions object.