Angular 离子空间中的变量和存储

Angular 离子空间中的变量和存储,angular,ionic-framework,ionic3,angular2-forms,Angular,Ionic Framework,Ionic3,Angular2 Forms,首先我有 <timer #timer [timeInSeconds]="this.store" timerFont></timer></p> 问题是this。balance值存储在RestProvider的函数中,但是如果我想从构造函数或其他函数调用this.balance,我将无法这样做。如何从RestProvidergetBalance()函数之外的函数中引用值?假设getBalance函数位于名为MyPage的页面组件中。然后你可以这样做: expor

首先我有

<timer #timer [timeInSeconds]="this.store" timerFont></timer></p>

问题是
this。balance
值存储在
RestProvider
的函数中,但是如果我想从
构造函数
或其他函数调用
this.balance
,我将无法这样做。如何从
RestProvider
getBalance()
函数之外的函数中引用值?

假设getBalance函数位于名为MyPage的页面组件中。然后你可以这样做:

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 ///
        });  
}
然后,根据调用getBalance()的位置,可以将对页面的引用作为参数传递。例如,如果从页面本身的某个位置呼叫,您会说:

this.getBalance(this);

你能详细说明你的疑问吗?
this.getBalance(this);