Reputation: 923
I have 2 functions and I'm trying to get the returned value of other function to continue but the returned value always undefined.
This is my code to return values.
export class HomePage {
variables={
a:1,
b:2,
c:3,
}
constructor(public navCtrl: NavController) {
this.function1();
}
function1(){
if(function2()){
alert("true");
}else{
alert("false");
}
}
function2(){
if(this.variables.a + this.variables.b >= this.variables.c){
return true;
}else{
return false;
}
}
}
Upvotes: 1
Views: 803
Reputation: 44669
Since you're declaring both functions as part of the component, you need to use the this
keyword to execute them:
function1(){
if(this.function2()){ // <--- like this!
alert("true");
}else{
alert("false");
}
}
Upvotes: 1