You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在app.component.html中渲染自定义Angular组件求助

解决Angular中'app-core'组件未识别的问题

问题原因

你的CoreModule虽然声明了CoreComponent,但没有导出这个组件。Angular模块内的组件默认仅对模块内部可见,外部模块(比如AppModule)导入该模块后,无法访问未导出的组件。

解决方案

修改core.module.ts,添加exports数组并将CoreComponent加入其中,让外部模块可以使用该组件:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { CoreComponent } from './core.component';

@NgModule({
  declarations: [
    CoreComponent
  ],
  imports: [
    CommonModule
  ],
  exports: [
    CoreComponent // 导出组件,供外部模块使用
  ]
})
export class CoreModule { }

额外验证步骤

  • 确认CoreModule在AppModule中的导入路径正确,确保文件位置没有变动
  • 重启Angular开发服务器(ng serve),避免缓存导致的识别问题

内容的提问来源于stack exchange,提问作者liberlux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 04:56:16