First of all I have
<timer #timer [timeInSeconds]="this.store" timerFont></timer></p>
I want the value of Timer to be grabbed from the function getBalance()
getBalance(){
this.restProvider.getBalance(this.user_id)
.then(data => {
this.todos = data;
this.balance = this.todos.balance;
this.timersecs = this.todos.timer;
/// HERE ///
});
}
The problem is this.balance
value is stored within the function of RestProvider
but if I want to call this.balance
from Constructor
or other function I won't be able to do so. How can I reference the value from functions outside of the RestProvider
getBalance()
function?
Lets suppose your getBalance function is in a page component called MyPage. Then you can do this:
export class MyPage {
balance: number;
getBalance(outerThis: MyPage){
this.restProvider.getBalance(this.user_id)
.then(data => {
this.todos = data;
outerThis.balance = this.todos.balance;
this.timersecs = this.todos.timer;
/// HERE ///
});
}
then depending on where you are calling getBalance() from, you would pass a reference to your page as a parameter. Eg if calling from somewhere within the page itself, you would say:
this.getBalance(this);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.