0

I am trying to create a custom component as header of all pages. I generated it using CLI command

ionic generate component BPNavbar

bp-navbar.html

<ion-header>
    <ion-navbar>
        <button ion-button ion-button menuToggle>
            <ion-icon name="menu"></ion-icon>
        </button>
        <ion-title text-left>LISTADO DE OFERTAS</ion-title>
        <ion-buttons end> 
            <button id="notification-button" ion-button clear (click)="openCart()">
                <ion-icon name="cart">
                    <ion-badge id="notifications-badge" color="danger">17</ion-badge>
                </ion-icon>              
            </button>        
        </ion-buttons>
    </ion-navbar>
</ion-header>

bp-navbar.ts

import { Component } from '@angular/core';

@Component({
    selector: 'bp-navbar',
    templateUrl: 'bp-navbar.html'
})
export class BpNavbarComponent {

    text: string;

    constructor() {
        console.log('Hello BpNavbarComponent Component');
        this.text = 'Hello World';
    }

}

components.module.ts

import { NgModule } from '@angular/core';
import { BpNavbarComponent } from './bp-navbar/bp-navbar';
@NgModule({
    declarations: [BpNavbarComponent],
    imports: [],
    exports: [BpNavbarComponent]
})
export class ComponentsModule {}

If I add tags

<bp-navbar></bp-navbar>

in one html page file I don't get any printed. I don't get any error.

Any idea why is not being rendered?

3
  • Is 'components.module.ts' your root module? Commented Jun 15, 2018 at 12:28
  • where is your IonicModule module Commented Jun 15, 2018 at 12:28
  • just added 'import { ComponentsModule } from '../components/components.module';' into app.module.ts without effect Commented Jun 15, 2018 at 12:44

1 Answer 1

1

While I don't know the details behind it, this is caused by the ion-header element being inside your component. Remove it from the component and place it on the page, and it should work. Each HTML page will then begin:

<ion-header>
  <bp-navbar></bpnavbar>
</ion-header>
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.