Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在NativeScript应用程序中获取屏幕度量_Angular_Nativescript_Angular2 Nativescript - Fatal编程技术网

Angular 在NativeScript应用程序中获取屏幕度量

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

如何在NativeScript Angular 2应用程序中访问

一个人是否应该使用DI系统的角度,注入屏幕度量?我想不会,因为尽管
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);
  }
}

谢谢最后我把
平台
包装成了一个
可注入的
角度服务。谢谢!我最终将
平台
包装成了一个
可注入的
角度服务。