I am new to application development with NativeScript and I will try to describe the whole situation and hopefully you will help me again to find a solution.
From my PHP experience, now I want to create a template for each "page" of the application. That template will have some partials templates (side drawer, action bar, content & bottom navigation), which must appear on each page.
I started implementing the bottom navigation as a component, and I am trying to display it in my home component, but it doesn't get displayed.
The "/" route is redirected to the "home". Here is the code:
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";
import { BottomNavComponent } from './bottom-nav/bottom-nav.component';
@NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule
],
declarations: [
AppComponent,
BottomNavComponent
],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class AppModule { }
app.component.html
<page-router-outlet></page-router-outlet>
import { Component, OnInit } from "@angular/core";
@Component({
selector: "Home",
templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {
constructor() {
// Use the component constructor to inject providers.
}
ngOnInit(): void {
// Init your component properties here.
}
}
home.component.html
<ActionBar>
<Label text="Title"></Label>
</ActionBar>
<StackLayout>
<label text="Content before"></label>
<ns-bottom-nav></ns-bottom-nav>
<label text="Content after"></label>
</StackLayout>
bottom-nav.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'ns-bottom-nav',
templateUrl: './bottom-nav.component.html',
styleUrls: ['./bottom-nav.component.css']
})
export class BottomNavComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
bottom-nav.component.html
<Button text="bottom-nav works!" class="btn btn-primary"></Button>
The files I have missed being with the default code for a new application, but if it is important I will include them.
home.module.ts, you might need to moveBottomNavComponentfrom the declarations array of theapp.module.tstohome.module.ts