Angular 在NativeScript应用程序中获取屏幕度量
如何在NativeScript Angular 2应用程序中访问 一个人是否应该使用DI系统的角度,注入屏幕度量?我想不会,因为尽管Angular 在NativeScript应用程序中获取屏幕度量,angular,nativescript,angular2-nativescript,Angular,Nativescript,Angular2 Nativescript,如何在NativeScript Angular 2应用程序中访问 一个人是否应该使用DI系统的角度,注入屏幕度量?我想不会,因为尽管Import语句很好,但下面的语句不起作用。我在控制台中看到奇怪的错误 import { Component } from '@angular/core'; import { ScreenMetrics } from 'platform'; @Component({ selector: 'home', templateUrl: 'components/ho
Import
语句很好,但下面的语句不起作用。我在控制台中看到奇怪的错误
import { Component } from '@angular/core';
import { ScreenMetrics } from 'platform';
@Component({
selector: 'home',
templateUrl: 'components/home/home.component.html',
})
export class HomeComponent {
constructor(private screenMetrics: ScreenMetrics) {
console.log(screenMetrics);
}
}
不幸的是,这些文档不是很完美,大多数代码示例都是纯JavaScript代码。在NativeScript Angular中,要获取有关屏幕的信息,您应该使用
从“平台”
导入{screen}。然后您就有了主屏幕,您可以在主屏幕上访问高度下降
,高度像素
,比例
,宽度下降
,宽度像素
属性。在下面的示例中,您可以回顾如何在NS中访问它们
import { Component } from '@angular/core';
import { screen } from 'platform';
@Component({
selector: 'home',
templateUrl: 'components/home/home.component.html',
})
export class HomeComponent {
constructor() {
console.dump(screen.mainScreen);
console.log(screen.mainScreen.widthPixels);
}
}
在NativeScript中,要获取有关屏幕的信息,应使用“平台”中的
import{screen}。然后您就有了主屏幕,您可以在主屏幕上访问高度下降
,高度像素
,比例
,宽度下降
,宽度像素
属性。在下面的示例中,您可以回顾如何在NS中访问它们
import { Component } from '@angular/core';
import { screen } from 'platform';
@Component({
selector: 'home',
templateUrl: 'components/home/home.component.html',
})
export class HomeComponent {
constructor() {
console.dump(screen.mainScreen);
console.log(screen.mainScreen.widthPixels);
}
}
谢谢最后我把平台
包装成了一个可注入的
角度服务。谢谢!我最终将平台
包装成了一个可注入的
角度服务。