我想使用打字机在离子2中获取设备宽度和高度。如何使用类型脚本获取Ionic 2中的设备宽度和高度?
在以前的版本离子2我用的,
window.screen.width
window.screen.height
但在较新的版本,这是行不通的。
它是如何与类型脚本+离子2?
我想使用打字机在离子2中获取设备宽度和高度。如何使用类型脚本获取Ionic 2中的设备宽度和高度?
在以前的版本离子2我用的,
window.screen.width
window.screen.height
但在较新的版本,这是行不通的。
它是如何与类型脚本+离子2?
可以使用Platform information这样的:
import {Component} from '@angular/core';
import {Platform} from 'ionic-angular';
@Component({...})
export MyApp {
constructor(platform: Platform) {
platform.ready().then((readySource) => {
console.log('Width: ' + platform.width());
console.log('Height: ' + platform.height());
});
}
}
就像你可以在离子文档看,国内的platform
使用window.innerWidth
和window.innerHeight
但
使用这种方法,因为尺寸首选是一个缓存值, 可以减少多次读取昂贵DOM的机会。
尝试使用window.innerHeight和window.innerWidth分别获取设备的高度和宽度。
感谢您的回复... –
感谢哥们,它工作正常。 –
这应该是被接受的答案,因为它符合离子标准2 –
是的。我认为是被接受的答案.. –