NativeScript 8.2:无法读取未定义的 属性 'portrait'
NativeScript 8.2 : Cannot read property 'portrait' of undefined
我在我的 NativeScript 8.2 版应用程序中使用 NativeScript-Orientation-Free 插件。
我的应用程序使用“tns 运行 ios”编译正常,但是
我在 运行 时间遇到错误,当我尝试设置方向时,我的应用程序崩溃了
Component
import { Component, OnInit } from '@angular/core';
import * as devOrientation from 'nativescript-orientation-free';
import { Item } from './item'
import { ItemService } from './item.service'
@Component({
selector: 'ns-items',
templateUrl: './items.component.html',
})
export class ItemsComponent implements OnInit {
items: Array<Item>
constructor(private itemService: ItemService) {}
ngOnInit(): void {
this.items = this.itemService.getItems();
devOrientation.setOrientation("portrait");
}
}
Error
Package.json
{
"name": "poc",
"main": "./src/main.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"@nativescript/angular": "^13.0.0",
"@nativescript/core": "~8.2.0",
"@nativescript/theme": "~3.0.2",
"nativescript-orientation-free": "2.2.5",
"rxjs": "~7.5.0",
"zone.js": "~0.11.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.0",
"@angular/compiler-cli": "~13.2.0",
"@nativescript/ios": "8.2.1",
"@nativescript/types": "~8.2.0",
"@nativescript/webpack": "~5.0.6",
"@ngtools/webpack": "~13.2.0",
"typescript": "~4.5.5"
}
}
Webpack.config.js
const webpack = require("@nativescript/webpack");
module.exports = (env) => {
webpack.init(env);
webpack.chainWebpack(config=>{
config.resolve.alias.set('tns-core-modules/application','@nativescript/core/application');
config.resolve.alias.set('tns-core-modules/ui/core/view-base','@nativescript/core/ui/core/view-base');
config.resolve.alias.set('tns-core-modules/ui/core/view','@nativescript/core/ui/core/view');
config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
config.resolve.alias.set('tns-core-modules/ui/frame','@nativescript/core/ui/frame');
config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
config.resolve.alias.set('tns-core-modules/ui/enums','@nativescript/core/ui/enums');
});
return webpack.resolveConfig();
};
tsConfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"skipLibCheck": true,
"lib": ["es2017", "dom"],
"baseUrl": ".",
"paths": {
"~/*": ["src/*"],
"@/*": ["src/*"]
}
},
"include": ["src/tests/**/*.ts", "src/**/*.ios.ts", "src/**/*.android.ts"],
"files": ["./src/main.ts", "./references.d.ts", "./src/polyfills.ts"],
"exclude": ["node_modules", "platforms", "e2e"]
}
我不想使用这个付费版本 NativeScript-Orientation。谁能告诉我如何修复或我遗漏了什么,或者我们有任何替代方法来设置方向吗?
我删除了第三方插件的方向并设置成这样
UIDevice.currentDevice.setValueForKey(currentOrientation, "orientation");
我在我的 NativeScript 8.2 版应用程序中使用 NativeScript-Orientation-Free 插件。
我的应用程序使用“tns 运行 ios”编译正常,但是 我在 运行 时间遇到错误,当我尝试设置方向时,我的应用程序崩溃了
Component
import { Component, OnInit } from '@angular/core';
import * as devOrientation from 'nativescript-orientation-free';
import { Item } from './item'
import { ItemService } from './item.service'
@Component({
selector: 'ns-items',
templateUrl: './items.component.html',
})
export class ItemsComponent implements OnInit {
items: Array<Item>
constructor(private itemService: ItemService) {}
ngOnInit(): void {
this.items = this.itemService.getItems();
devOrientation.setOrientation("portrait");
}
}
Error
Package.json
{
"name": "poc",
"main": "./src/main.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"@nativescript/angular": "^13.0.0",
"@nativescript/core": "~8.2.0",
"@nativescript/theme": "~3.0.2",
"nativescript-orientation-free": "2.2.5",
"rxjs": "~7.5.0",
"zone.js": "~0.11.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.0",
"@angular/compiler-cli": "~13.2.0",
"@nativescript/ios": "8.2.1",
"@nativescript/types": "~8.2.0",
"@nativescript/webpack": "~5.0.6",
"@ngtools/webpack": "~13.2.0",
"typescript": "~4.5.5"
}
}
Webpack.config.js
const webpack = require("@nativescript/webpack");
module.exports = (env) => {
webpack.init(env);
webpack.chainWebpack(config=>{
config.resolve.alias.set('tns-core-modules/application','@nativescript/core/application');
config.resolve.alias.set('tns-core-modules/ui/core/view-base','@nativescript/core/ui/core/view-base');
config.resolve.alias.set('tns-core-modules/ui/core/view','@nativescript/core/ui/core/view');
config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
config.resolve.alias.set('tns-core-modules/ui/frame','@nativescript/core/ui/frame');
config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
config.resolve.alias.set('tns-core-modules/ui/enums','@nativescript/core/ui/enums');
});
return webpack.resolveConfig();
};
tsConfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"skipLibCheck": true,
"lib": ["es2017", "dom"],
"baseUrl": ".",
"paths": {
"~/*": ["src/*"],
"@/*": ["src/*"]
}
},
"include": ["src/tests/**/*.ts", "src/**/*.ios.ts", "src/**/*.android.ts"],
"files": ["./src/main.ts", "./references.d.ts", "./src/polyfills.ts"],
"exclude": ["node_modules", "platforms", "e2e"]
}
我不想使用这个付费版本 NativeScript-Orientation。谁能告诉我如何修复或我遗漏了什么,或者我们有任何替代方法来设置方向吗?
我删除了第三方插件的方向并设置成这样
UIDevice.currentDevice.setValueForKey(currentOrientation, "orientation");