Javascript can';无法使ionic v4 CLI生成的组件正常工作

Javascript can';无法使ionic v4 CLI生成的组件正常工作,javascript,angular,typescript,ionic-framework,Javascript,Angular,Typescript,Ionic Framework,我目前正在使用最新的Ionic,我很难让CLI生成组件正常工作 我从一个空白项目开始,然后使用以下内容创建一个新组件: ionic generate component my-component 该命令运行正常,并创建以下文件: CREATE src/app/my-component/my-component.component.html (31 bytes) CREATE src/app/my-component/my-component.component.spec.ts (664 byt

我目前正在使用最新的Ionic,我很难让CLI生成组件正常工作

我从一个空白项目开始,然后使用以下内容创建一个新组件:

ionic generate component my-component
该命令运行正常,并创建以下文件:

CREATE src/app/my-component/my-component.component.html (31 bytes)
CREATE src/app/my-component/my-component.component.spec.ts (664 bytes)
CREATE src/app/my-component/my-component.component.ts (293 bytes)
CREATE src/app/my-component/my-component.component.scss (0 bytes)
然后我继续在主页中使用新组件,如下所示:

<ion-content padding>
<my-component></my-component>
</ion-content>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { MyComponentComponent } from './my-component/my-component.component';

@NgModule({
  declarations: [AppComponent, MyComponentComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
在爱奥尼亚实验室运行应用程序时,我发现以下错误:

错误:未捕获(承诺中):错误:模板分析错误: “我的组件”不是已知元素 这是我的系统信息:

ionic (Ionic CLI)             : 4.2.1 
Ionic Framework               : @ionic/angular 4.0.0-beta.12
@angular-devkit/build-angular : 0.7.5
@angular-devkit/schematics    : 0.7.5
@angular/cli                  : 6.1.5
@ionic/angular-toolkit        : 1.0.0
你知道为什么会这样吗?我以前用过爱奥尼亚3,从来没有遇到过这个问题

更新:

这是我的默认my-component.component.ts文件:

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

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.scss']
})
export class MyComponentComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

为了在另一个组件中使用自定义组件,必须将其包含在
导出
数组中

@NgModule({
  ....
  declarations: [AppComponent, MyComponentComponent],
  entryComponents: [],
  exports:[MyComponentComponent]
  ....
})
export class AppModule {}
您可以这样做,也可以在另一个
customModule
中创建所有自定义组件,然后在
app.component.ts
页面中导入该模块


您所指的组件名称是错误的。您的
MyComponentComponent
类的选择器是
app my component
,因此您必须使用
而不是

MyComponentComponent是错误的。你使用的是最新版本的框架吗?你能分享我的组件代码吗?我会用代码更新我的问题。谢谢!我试过了,但还是没能成功。我将“自定义元素模式”添加到ngmodule.schemas中,错误消失了,但组件也没有加载。