Ionic2,如何在初始化期间获取contentHeight

时间:2017-01-27 17:38:24

标签: initialization ionic2

当我第一次切换到标签页时,我想使用contentHeight的{​​{1}}进行一些初始化,但我找不到正确的位置。这是我做的:

ion-content

运行并单击按钮时,结果为:

import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController, Content } from 'ionic-angular';

@Component({
  selector: 'page-test',
  templateUrl: 'test.html'
})
export class TestPage {
  @ViewChild(Content) content : Content;

  constructor(private nav: NavController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad');
    console.log('\tcontentHeight', this.content.contentHeight);
    console.log('\tscrollHeight', this.content.scrollHeight);

    let element = this.content.getScrollElement();
    console.log('\tclientHeight', element.clientHeight);
  }

  doClick() {
    console.log('doClick');
    console.log('\tcontentHeight', this.content.contentHeight);
    console.log('\tscrollHeight', this.content.scrollHeight);

    let element = this.content.getScrollElement();
    console.log('\tclientHeight', element.clientHeight);
  }
}

单击按钮后显示的值是我需要的值,但在初始化期间我需要它们。在完全初始化所有内容之前,似乎会调用ionViewDidLoad contentHeight – 0 scrollHeight – 0 clientHeight – 568 doClick contentHeight – 475 scrollHeight – 569 clientHeight – 475

如何正确初始化?

0 个答案:

没有答案