当我第一次切换到标签页时,我想使用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
。
如何正确初始化?