我想创建一个简单的组件并将其包含在页面中。我使用ionic g component my-header
(ionic-cli v3 beta)创建了它,修复了IonicPageModule错误,然后添加到另一个页面。然后我得到这个错误:离子v3中的自定义组件
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声明。
感谢您的帮助。
编辑:
该组件位于我的components
文件夹内:
组件/我的报头/我的-了header.html
<div>
{{text}}
</div>
组件/我的报头/我的报头.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 {}
components/my-header/my-header.scss
my-header {}
组件/我的头/我-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';
}
}
应用程序/ app.module.ts
/* imports */
import { MyHeaderComponent } from '../components/my-header/my-header';
@NgModule({
declarations: [
MyApp,
MyHeaderComponent
],
...
页/家庭/ home.html的
你的组件有单独的module.ts文件吗? –
是的,我添加了与组件相关的整个代码 –