Я пытаюсь поделиться угловым кодом веб-приложения с Native Script, но я получаю следующую ошибку, если я использую существующий код, и он не появляется, когда я рендеринг нового компонента только для мобильных приложений.
Вызов метода js onCreate не выполнен
Ошибка
Successfully synced application com.asm on device ZY322BS2GQ.
JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.asm/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
System.err:
System.err: TypeError: Cannot read property 'create' of undefined
System.err: File: "file:///data/data/com.asm/files/app/vendor.js, line: 12530, column: 14
System.err:
System.err: StackTrace:
System.err: Frame: function:'', file:'file:///data/data/com.asm/files/app/vendor.js', line: 12530, column: 15
System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame-common.js.FrameBase.navigate', file:'file:///data/data/com.asm/files/app/vendor.js', line: 20118, column: 30
System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/com.asm/files/app/vendor.js', line: 21508, column: 30
System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.onCreate', file:'file:///data/data/com.asm/files/app/vendor.js', line: 21352, column: 14
System.err: Frame: function:'push.../node_modules/tns-core-modules/ui/frame/activity.js.NativeScriptActivity.onCreate', file:'file:///data/data/com.asm/files/app/vendor.js', line: 19268, column: 25
System.err:
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2861)
System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
System.err: at android.app.ActivityThread.-wrap11(Unknown Source:0)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
System.err: at android.os.Looper.loop(Looper.java:164)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6626)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
System.err: Caused by: com.tns.NativeScriptException:
System.err: Calling js method onCreate failed
App-routing.module.tns.ts
ВВ этом файле я использую NativeScriptRouterModule в качестве оболочки для использования функций маршрутизации в собственных приложениях
import { NgModule } from '@angular/core';
import { NativeScriptRouterModule } from 'nativescript-angular/router';
import { Routes } from '@angular/router';
import { ErrorComponent } from './component/error-page/error-page.component';
import { Common } from '@helper/app.common';
import { AppRouter } from '@router/app-router';
import { QuestionRouter } from '@router/question-router';
export const routes: Routes = [
{path: '', component: ErrorComponent},
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(Common.mergeStates(AppRouter.states, QuestionRouter.states))],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }
App-router.tns.ts
Я поддерживаю состояния вмое приложение для отображения правильных компонентов
import { Injectable } from "@angular/core";
import { ErrorComponent } from "../../component/error-page/error-page.component";
import { StateService } from "@uirouter/core";
import { QuestionInterfaceComponent } from "../../component/question-interface/question-interface.component";
import { Constant } from "@helper/app.constants";
import { Common } from "@helper/app.common";
import { VideoInterfaceComponent } from "src/app/component/video-interface/video-interface.component";
@Injectable({
providedIn: 'root'
})
export class AppRouter {
static states: any = {
states: [
{
name: Constant.ROUTER_STATES.Question,
// component: QuestionInterfaceComponent
component: ErrorComponent
},
{
name: Constant.ROUTER_STATES.Video,
// component: VideoInterfaceComponent
component: ErrorComponent
},
{
name: Constant.ROUTER_STATES.Error,
component: ErrorComponent,
params: {
msg: null
}
}
]
};
constructor(private stateService: StateService) { }
load(state: string, msg?: string) {
this.stateService.go(state, { msg: msg });
Common.hideLoader();
}
}