0

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 
  }
});
Zaza
  • 406
  • 9
  • 18
  • How do you call the getResult function is important here. without the relevant code, this question is not answerable. voting to close – Ember Freak Apr 25 '18 at 19:44

2 Answers2

0

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.

Lux
  • 17,835
  • 5
  • 43
  • 73
  • that *is* the answer. your code is correct. if that wasnt your problem, you dont have a problem (or dont post the relevant code). – Lux Apr 23 '18 at 09:21
  • i haven't access the getValue() its return this.getValue is not function – Zaza Apr 24 '18 at 05:39
  • have you checked the twittle I linked? it works! If this does *not* work for you please provide a minimal not working example like a git repo or a twiddle. – Lux Apr 24 '18 at 12:15
  • for that you have access the method inside actions but i need this in custom function – Zaza Apr 25 '18 at 12:26
  • how do you call this custom function? please show this code. probably there is your error. – Lux Apr 25 '18 at 12:39
0

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.

cs95
  • 379,657
  • 97
  • 704
  • 746
Paul
  • 18,349
  • 7
  • 49
  • 56
  • its simple i can get the hash url from the window location and then check the last path of the url so i can make little function inside the controller to check the last path of the url (i know it will done by helper function ) so when calling the controller custom function inside the custom function i need to call that url check custom function i have tried but its return the function is not defined sorry I have not share my whole codes here – Zaza Apr 25 '18 at 12:32