2016-08-03 107 views

回答

48

可以使用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.innerWidthwindow.innerHeight

使用这种方法,因为尺寸首选是一个缓存值, 可以减少多次读取昂贵DOM的机会。

+1

感谢哥们,它工作正常。 –

+3

这应该是被接受的答案,因为它符合离子标准2 –

+1

是的。我认为是被接受的答案.. –

3

尝试使用window.innerHeight和window.innerWidth分别获取设备的高度和宽度。

+0

感谢您的回复... –