我想创建一个简单的组件并将其包含在页面上。我用它创建了ionic g component my-header
(ionic-cli v3 beta),修复了IonicPageModule bug,然后添加到另一个页面。然后我得到这个错误:
Error: Uncaught (in promise): Error: Template parse errors:
'my-header' is not a known element:
1. If 'my-header' is an Angular component, then verify that it is part of this module.
2. If 'my-header' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
“MyHeaderComponent”已自动添加到 @NgModule 声明中。
感谢您的帮助。
EDIT:
该组件位于我的内部components
folder:
组件/my-header/my-header.html
<div>
{{text}}
</div>
组件/my-header/my-header.module.ts
import { NgModule } from '@angular/core';
import { IonicModule } from 'ionic-angular';
import { MyHeaderComponent } from './my-header';
@NgModule({
declarations: [
MyHeaderComponent,
],
imports: [
IonicModule,
],
exports: [
MyHeaderComponent
],
entryComponents:[
MyHeaderComponent
]
})
export class MyHeaderComponentModule {}
组件/my-header/my-header.scss
my-header {}
组件/my-header/my-header.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-header',
templateUrl: 'my-header.html'
})
export class MyHeaderComponent {
text: string;
constructor() {
console.log('Hello MyHeaderComponent Component');
this.text = 'Hello World';
}
}
应用程序/应用程序模块.ts
/* imports */
import { MyHeaderComponent } from '../components/my-header/my-header';
@NgModule({
declarations: [
MyApp,
MyHeaderComponent
],
...
页面/home/home.html