NativeScript 8.2:无法读取属性“肖像”;未定义的
我在 NativeScript 版本 8.2 应用程序中使用 NativeScript-Orientation-Free 插件。
我的应用程序可以通过“tns run ios”编译良好,但是 当我尝试设置方向时,运行时出现以下错误并且我的应用程序崩溃
组件
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");
}
}
错误
包.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。谁能告诉我如何修复或我缺少什么,或者我们有任何替代方法来设置方向吗?
I am using NativeScript-Orientation-Free Plugin in my NativeScript version 8.2 Application.
My app is compiling fine with "tns run ios" but
I am getting below Error on the run time and my app crashes When I am trying to set the orientation
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"]
}
i do not want to use this paid version NativeScript-Orientation. can anyone tell me how can I fix or what i am missing or do we have any alternate to set the orientation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我删除了第三方插件以进行方向设置并像这样设置
i removed the third party plugins for orientation and setting it like this