Angular / Ionic:来自其他功能的访问功能属性

时间:2017-07-13 16:21:33

标签: javascript angular ionic-framework packery

我正在使用Packery来让我的卡更好地流动,并且我在一个名为ionViewDidEnter()的函数中初始化网格。

ionViewDidEnter() {
  this.clientService.clientStream$.subscribe(
    client => {
      this.client = client;  
      this.setupGrid();
    }
  )
}

setupGrid() {

  setTimeout(()=> {

    var elem = document.querySelector('.pckry-grid');

    var pckry = new Packery( elem, {
      itemSelector: ".grid-item"
    });

    // Resets the grid after elements have loaded
    pckry.layout()

    // attempt at saving pckry object to component variable
    this.packery = pckry

    console.log(this.packery)

  }, 1);
}

但是,当布局发生变化时,我需要能够从检测到变化的函数中调用pckry.layout()。我试过以下没有运气:

// this is called when a form input is changed and I'd like to refresh the layout
formHasChanged() {
  this.formChanged = true;
  this.setupGrid();
}

我尝试在this.packery.layout()内调用formHasChanged(),但这也无效。有没有更好的方法来引用它?

0 个答案:

没有答案