Ionic 2:在与 UI 交互之前,数据模型的更改不会在 UI 中更新

Ionic 2: Changes in data model not updated in UI until interaction with UI

问)为什么我的数据变化没有显示在 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 列表不会出现在 UI 中,直到我与应用程序交互,例如单击菜单按钮,或聚焦搜索字段。

确保您已升级到 beta.6 并遵循以下指南(因为除了更新 package.json 中的依赖项外,几乎没有必要的更改)

  1. 将 Ionic CLI 更新到最新版本 version:npm install -g ionic@beta

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

  3. 从 app.ts/app.js.

  4. 中删除行 import 'es6-shim'
  5. 在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>
    
  6. 更新您的 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", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "zone.js": "^0.6.11" }

  7. 在你的 package.json 更新 ionic-gulp-scripts-copy 的版本到 ^1.0.1.

  8. 从项目文件夹中 运行 npm install 安装新包。

  9. 查看 changelog149 以了解重大更改并相应地更新您的项目。

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