I want to create a reusable header to my app. So, I did:
Created the component (app-header):
app-header.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: 'app-header.html'
})
export class AppHeaderComponent {
text: string;
constructor() {
console.log('Hello AppHeaderComponent Component');
this.text = 'Hello World';
}
}
That have the HTML:
app-header.html:
<div>
{{text}}
</div>
And I've added the AppHeaderComponent to declarations in @NgModule:
...
import { AppHeaderComponent } from '../components/app-header/app-header';
@NgModule({
declarations: [
MyApp,
TabsPage,
AppHeaderComponent
],
...
I'm using TabsTemplate and I want to add this component in every tab, so, I did on feed.html (one of my tabs):
<app-header></app-header>
<ion-content>
...
But it gives tthe following error:
Uncaught Error: Template parse errors: 'app-header' is not a known element: 1. If 'app-header' is an Angular component, then verify that it is part of this module. 2. If 'app-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (" -->
[ERROR ->]
So, I changed app-header.ts to:
import { Component, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: 'app-header.html'
})
@NgModule({
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppHeaderComponent {
text: string;
constructor() {
console.log('Hello AppHeaderComponent Component');
this.text = 'Hello World';
}
}
But the same error still here.
How can I do this?
Update:
I'm using Tabs, so, I have:
tabs.ts:
import { Component } from '@angular/core';
import { FeedPage } from '../feed/feed';
import { AboutPage } from '../about/about';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tabFeed = FeedPage;
tabAbout= AboutPage;
constructor() {
}
}
And tabs.html:
<ion-tabs>
<ion-tab [root]="tabFeed" tabIcon="paper"></ion-tab>
<ion-tab [root]="tabAbout" tabIcon="search"></ion-tab>
</ion-tabs>
And each tab load a page, like feed.html (quoted in the question)
Code architecture:
And components.modules.ts have:
import { NgModule } from '@angular/core';
import { AppHeaderComponent } from './app-header/app-header';
@NgModule({
declarations: [AppHeaderComponent],
imports: [],
exports: [AppHeaderComponent]
})
export class ComponentsModule {}

CUSTOM_ELEMENTS_SCHEMAin question... What is the doubt?