harish mahajan harish mahajan - 1 month ago 14
TypeScript Question

How to get height and width of device in angular2 using typescript?

I found this solution. Is it valid?

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());
});
}
}


This solution is for ionic 2.
can i also used for angular 2?

Please suggest me the right way to do it.

Answer
export class Dashboard {
    innerHeight: any;
    innerWidth: any;
    constructor(private router: Router, private http: Http) {
        this.innerHeight = (window.screen.height) + "px";
        this.innerWidth = (window.screen.width) + "px";
    }
}