我正在try 使用typescript获得ionic 2中的设备宽度和高度.
在我之前使用的爱奥尼亚2版本中,
window.screen.width
window.screen.height
但在新版本中,这是行不通的.
如何使用类型脚本+ionic 2?
我正在try 使用typescript获得ionic 2中的设备宽度和高度.
在我之前使用的爱奥尼亚2版本中,
window.screen.width
window.screen.height
但在新版本中,这是行不通的.
如何使用类型脚本+ionic 2?
您可以使用平台信息进行此操作.
在内部,platform
使用window.innerWidth
和window.innerHeight
,但
首选使用此方法,因为维度是缓存的值,
Docs: https://ionicframework.com/docs/angular/platform#width-number
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
@Component({...})
export MyApp {
constructor(platform: Platform) {
platform.ready().then(() => {
console.log('Width: ' + platform.width());
console.log('Height: ' + platform.height());
});
}
}
Docs: https://ionicframework.com/docs/v3/api/platform/Platform/#width
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
@Component({...})
export MyApp {
constructor(platform: Platform) {
platform.ready().then(() => {
console.log('Width: ' + platform.width());
console.log('Height: ' + platform.height());
});
}
}