首页 文章

嵌入式Nativescript Angular代码到现有iOS项目中,Angular 7抛出错误:错误:必须使用框架导航到页面

提问于
浏览
1

当我使用嵌入式nativescript框架和nativescript代码运行iOS xcode项目时,在尝试向xcode控制台显示/加载nativescript页面时,应用程序会出错: Error: Error: A Frame must be used to navigate to a Page.

下面是我的Objective-c函数,它开始加载NativeScript页面 .

- (NSString*) scriptStringToLoad {
    NSString *source = @"var platform_1 = require('nativescript-angular/platform');"
    "var app_module_1 = require('./app/app.module');"
    "var platform = platform_1.platformNativeScriptDynamic();"
    "platform.bootstrapModule(app_module_1.AppModule);";

    return  source;
}

以下是NativeSctipt部分:

app.module.ts文件代码

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";

@NgModule({
    bootstrap: [
        AppComponent
    ],
    imports: [
        NativeScriptModule,
        AppRoutingModule
    ],
    declarations: [
        AppComponent
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class AppModule { }
  • app.component.ts文件代码

从@ @ angular / core导入;

@Component({moduleId:module.id,selector:“ns-app”,templateUrl:“app.component.html”})export class AppComponent {

onButtonTap() {
    console.log('Hi hello button tapped');
}

}

  • app.component.html文件代码

1 回答

  • 0

    你的app.component.html应该只有

    <page-router-outlet></page-router-outlet>
    

    为了构建你可以使用tns build with --bundle flag来启用webpack构建和检查 .

    您可以按照此游乐场示例中的结构进行操作 - play.nativescript.org/?template=play-ng&id=iayuat

相关问题