0

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.

5
  • is the home component being lazy loaded? Commented May 15, 2020 at 12:34
  • I don't know :( I will edit the post to add the home.component.ts Commented May 15, 2020 at 13:01
  • 1
    if you have a home.module.ts, you might need to move BottomNavComponent from the declarations array of the app.module.ts to home.module.ts Commented May 15, 2020 at 13:12
  • thank you. this have worked. is this the lazy loading? Commented May 15, 2020 at 15:11
  • Yes (based on the code snippets you have). If you want to use a component inside another component, you will have to either have both components declared in the same module or have the module import the other module containing the component (if they are in separate modules) Commented May 15, 2020 at 15:32

1 Answer 1

1

The default route should be "" not "/" that's why u are not being redirect to home, and also u need to move ur bottom nav component inside the home module.

You can find a better example in the Nativescript docs or the marketplace where u can find templates ready to use.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.