2016-09-23 78 views
0

我想在我的頁面顯示一些項目(來自SqLite數據庫)。但是,當我嘗試檢索這些項目時,需要很長的時間(如1分鐘),即使只有1條記錄,也可以使用Ionic 2的性能問題應用程序

PS:它只是發生在頁和上僅第一次,換句話說,如果我嘗試渲染頁面再次它會非常快。

這裏是我的代碼:

服務:

all(): any { 
    return this.storage.query('SELECT * FROM table'); 
} 

頁:

import {Component} from '@angular/core'; 

import { SomeService } from 'path/service'; 

export class HomePage { 
    private items: Array<any>; 

    constructor(private service: SomeService) { 
     this.service.all().then(response => { 
      this.items = response.res.rows; 
     }); 
    } 

它是一個已知的問題還是什麼?

任何幫助,將不勝感激。

回答

0

嘗試使用觀測量:

服務:

import { Observable } from 'rxjs/Observable'

[...]

all(): Observable<any> { 
    let allItemsObs = Observable.create(observable => { 
     observable.next(this.storage.query('SELECT * FROM table')); 
    }) 
    return allItemsObs 
} 

頁:

constructor(private service: SomeService) { 
    this.service.all().subscribe(response => { 
     this.items = response.res.rows; 
    }); 
}