【问题标题】:Variables and Storage in ionic 3 Angularionic 3 Angular中的变量和存储
【发布时间】:2018-02-23 14:02:08
【问题描述】:

首先我有

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

我希望从函数getBalance()中获取Timer的值

getBalance(){
    this.restProvider.getBalance(this.user_id)
        .then(data => {
            this.todos = data;
            this.balance = this.todos.balance;
            this.timersecs = this.todos.timer;
            /// HERE ///
        });  
}

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

【问题讨论】:

  • 能否详细说明您的查询?

标签: angular ionic-framework ionic3 angular2-forms


【解决方案1】:

假设您的 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 2019-04-19
    • 2018-03-10
    相关资源
    最近更新 更多