2016-04-28 53 views
4

Q)爲什麼我的數據中的更改沒有在UI上顯示,例如項目列表,但只要我與UI交互,它們就會奇蹟般地出現?Ionic 2:數據模型中的更改未在UI中更新,直到與UI交互爲止

例如,如果我得到一個綁定到一個列表中的一些數據,然後更新該名單,像這樣:

this._LocalStorageService.getClients().then(
    (data) => {  
    this.clients = (data.res.rows.length == 1) ? <Client[]>JSON.parse(data.res.rows.item(0).clients) : []; 
    this.showNoDataPresent = (this.clients.length == 0); 
    }, 
    (error) => { 
    this._LogService.error(JSON.stringify(error.err)); 
    } 
); 

clients列表不顯示在用戶界面,直到我與互動該應用程序,例如點擊菜單按鈕或聚焦搜索欄。

+1

我也有類似的問題,這個問題是我在那裏執行請求。我的建議是爲任何需要更新視圖的異步調用避免使用'ngOnInit','onPageWillEnter'和'onPageLoaded'。我不得不使用'onPageDidEnter()'在有載異步調用之後使視圖更新。 –

+0

謝謝,但這正是「onPageWillEnter」和「ngOnInit」的意思!這個錯誤被證實與角度2中的無聲故障有關。我現在使用'onPageWillEnter' /'ngOnInit'完全沒有問題,因此如果您有任何其他問題,您可能需要重新訪問它們。乾杯。 – Dave

回答

2

確保您已升級到beta.6並遵守下列指南(因爲有除了更新中的package.json依賴少數的變更)

  1. 更新愛奧尼亞CLI到最新版本:npm install -g離子@ beta

  2. 如果您使用Ionic 2.0.0-beta.3或更早版本升級項目,請首先查看以下指南。

  3. 從app.ts/app.js中刪除行導入'es6-shim'。

  4. 之前在index.html文件angular2-polyfill.js添加ES6-shim.min.js:

    <script src="build/js/es6-shim.min.js"></script> 
        <!-- Zone.js and Reflect-metadata --> 
        <script src="build/js/angular2-polyfills.js"></script> 
        <!-- the bundle which is built from the app's source code --> 
        <script src="build/js/app.bundle.js"></script> 
    
  5. 更新您的package.json(不要複製粘貼&使用這些作爲參考並更新文件中的文件):

    「dependencies」:{「angular2」:「2.0.0-beta.15」,「es6-shim」:「^ 0.35.0」, 「ionic-angular 「:2.0.0-beta.6」, 「ionic-native」:「^ 1.1.1」, 「ionicons」:「3.0.0-alpha.3」, 「反映了元數據」: 「0.1.2」, 「rxjs」: 「5.0.0-beta.2」, 「zone.js」: 「^ 0.6.11」 }

  6. 在你的包.json將ionic-gulp-scripts-copy的版本更新爲^ 1.0.1。

  7. 從項目文件夾內部運行npm install來安裝新軟件包。

  8. 查看更改日誌149以瞭解更改並相應地更新您的項目。

來源:https://forum.ionicframework.com/t/ionic-2-projects-updating-to-beta-6/50049