【发布时间】:2017-02-14 18:32:05
【问题描述】:
我找到了这个解决方案。有效吗?
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());
});
}
}
此解决方案适用于离子 2。 我也可以用于角度 2 吗?
请给我建议正确的方法。
【问题讨论】:
-
回答你的问题,不。这在 Angular 2 中不是有效的方式,因为 Ionic 不是 Angular 的一部分,反之亦然。您仍然可以使用“窗口”获取客户端的高度/宽度
-
@JoeriShoeby:- 是的,现在我正在尝试宽度:window.innerWidth,高度:window.innerHeight 但我收到错误消息。 [ts] 找不到命名空间“窗口”。
-
这是因为您的 Typescript 编译器不知道“窗口”。您可能需要安装类型以确保您的编译器能够识别它。
-
@JoeriShoeby:- 对。但是如何安装呢?
-
您是否已经安装了任何类型?如果没有,首先使用 'sudo npm install -g typings' 安装类型
标签: angular typescript