我面临一个大问题。我已经发布了类似的问题,但没有得到任何答案。
我将使用Angular 7版开发的Web应用程序迁移到NativeScript移动应用程序。
该Web应用程序在路径 src / app / model 中已经有一些TypeScript类。
路径 src / app / model / User.ts 中的User.ts示例:
export class User {
username: string;
password: string;
}
我在路径 src / app / shared-modules / navigation / create-user / first-step / first-step.component.tns.ts 中有一个组件>:
import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { User } from 'app/model/User';
@Injectable({
providedIn: "root"
})
export class UserLoginService {
user: User = new User();
constructor() {}
}
我试图将 User.ts 文件导入 first.step.component.tns.ts ,但是会引发错误:
“主”线程上发生未捕获的异常。 java.lang.RuntimeException:无法创建应用程序 com.tns.NativeScriptApplication:com.tns.NativeScriptException:
错误调用模块功能
无法编译 /data/data/org.nativescript.ngsample/files/app/bundle.js
SyntaxError:意外令牌!文件: “ file:///data/data/org.nativescript.ngsample/files/app/bundle.js, 行:465,列:28
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
SyntaxError:意外令牌!文件:“,行:1,列:265
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
SyntaxError:意外令牌!文件:“,行:1,列:265
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876) 在android.app.ActivityThread.access $ 1100(ActivityThread.java:199) 在 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1650) 在android.os.Handler.dispatchMessage(Handler.java:106) android.os.Looper.loop(Looper.java:193)在 android.app.ActivityThread.main(ActivityThread.java:6669)在 java.lang.reflect.Method.invoke(本机方法)位于 com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 引起原因:com.tns.NativeScriptException:
错误调用模块功能
无法编译 /data/data/org.nativescript.ngsample/files/app/bundle.js
SyntaxError:意外令牌!文件: “ file:///data/data/org.nativescript.ngsample/files/app/bundle.js, 行:465,列:28
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
SyntaxError:意外令牌!文件:“,行:1,列:265
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
SyntaxError:意外令牌!文件:“,行:1,列:265
StackTrace:框架:功能:'require',file:'',行:1,列:266 框架:功能:'', 文件:“ file:///data/data/org.nativescript.ngsample/files/app/starter.js”, 行:3,列:1框架:功能:'require',file:'',行:1, 列:266
位于com.tns.Runtime.runModule(本机方法)处 com.tns.Runtime.runModule(Runtime.java:624)在 com.tns.Runtime.run(Runtime.java:616)位于 com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21) 在 android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154) 在 android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871) ...另外8个
我的 tsconfig.tns.json 文件:
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"lib": [
"es6",
"dom"
],
"baseUrl": "src",
"paths": {
"~/*": [
"./*"
],
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
}
}
我想念什么?
答案 0 :(得分:0)
例如,尝试在构造函数中声明模型类,例如:-
import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { User } from 'app/model/User';
@Injectable({
providedIn: "root"
})
export class UserLoginService {
public user: User;
constructor() {
this.user = new User();
}
}