更新方向更改视图

时间:2018-11-22 13:43:26

标签: angular2-nativescript

我已经这样注册了一个directionChangedEvent:

app.on(app.orientationChangedEvent, (args: OrientationChangedEventData) => {
  if (this.currentScreenWidth === screen.mainScreen.widthDIPs) {
    this.currentScreenWidth = screen.mainScreen.heightDIPs;
  } else {
    this.currentScreenWidth = screen.mainScreen.widthDIPs;
  }
  this.configureGrid();
});

我有以下模板:

<GridLayout [rows]="rows" [columns]="columns">
<ng-container *ngFor="let card of cards">
  <StackLayout [row]="card.row" [col]="card.col" [colSpan]="card.colSpan">
    <kirby-card>
      <kirby-card-header [title]="'row: ' + card.row" [subtitle]="'col: ' + card.col">
      </kirby-card-header>
      <StackLayout class="content">
        <Label text="Here you can add stuff, which is cool."></Label>
      </StackLayout>
      <kirby-card-footer>
        <kirby-button label="Dummy Kirby Button" expand="block" shape="round" theme="cookbook"></kirby-button>
      </kirby-card-footer>
    </kirby-card>
  </StackLayout>
</ng-container>

,在我的configureGrid方法中,我更新了行,列和卡的属性,但是我的视图没有更新,该视图(GridLayout)的显示与旋转之前的显示完全相同。我已经注销了所有数据,但是我的数据确实发生了变化,因此似乎数据绑定不了解该数据已发生变化。

我可以以某种方式强制更新视图,或者如何解决此问题?

谢谢

1 个答案:

答案 0 :(得分:0)

使用NgZone进行数据更新,一切都很好。

相关问题