【发布时间】:2018-10-12 12:54:46
【问题描述】:
我正在用 NativeScript 编写我的第一个应用程序,但我对前端开发不太熟悉。我刚刚开始,并创建了一个带有两个按钮的简单的第一个屏幕。当按下一个按钮时,它应该导航到另一个屏幕。我已经添加了基于基本教程的路线,但现在该应用程序根本没有显示任何内容。我不确定如何调试问题或查看任何可以帮助我找出问题所在的日志/错误。 这是我的代码:
app.routing.module.ts
import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
const routes: Routes = [
{ path: "", redirectTo: "/home", pathMatch: "full" },
{ path: "home", loadChildren: "./home/home.module#HomeModule" },
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }
home-routing-module.ts
import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { HomeComponent } from "./home.component";
import { MathComponent } from "../math/math.component";
const routes: Routes = [
{ path: "", component: HomeComponent },
{ path: "math", component: MathComponent }
];
@NgModule({
imports: [NativeScriptRouterModule.forChild(routes)],
exports: [NativeScriptRouterModule]
})
export class HomeRoutingModule { }
export const navigatableComponents = [
MathComponent
];
home.component.html
<GridLayout>
<ScrollView class="page">
<StackLayout class="home-panel">
<Label textWrap="true" text="Test" class="h2 description-label"></Label>
<Button text="Math" (tap)="onMathTap()"></Button>
</StackLayout>
</ScrollView>
</GridLayout>
home.component.ts
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
onMathTap(): void {
console.log("Math was pressed");
this.router.navigate(["/math"])
}
constructor(private router: Router) { }
ngOnInit(): void {
}
}
app.modules.ts
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 { }
【问题讨论】: