Jig*_*hta 34 typescript ionic-framework ionic2 ionic3 angular
我试图使用打字稿获取离子2中的设备宽度和高度.
在以前版本的离子2我用过,
window.screen.width
window.screen.height
Run Code Online (Sandbox Code Playgroud)
但在较新版本中,这不起作用.
如何使用Type Script + ionic 2?
seb*_*ras 81
您可以使用这样的平台信息:
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());
});
}
}
Run Code Online (Sandbox Code Playgroud)
就像你在Ionic docs中看到的那样,在内部platform使用the window.innerWidth和window.innerHeightbut
使用此方法是首选,因为维度是缓存值,这减少了多次和昂贵的DOM读取的机会.
| 归档时间: |
|
| 查看次数: |
28726 次 |
| 最近记录: |