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

Angular报错NG8004:未找到名为uppercase的管道问题求助

解决NG8004: No pipe found with name 'uppercase'错误(独立Angular组件场景)

这个错误的核心原因是:Angular独立组件不会自动继承任何模块的导出内容,而uppercase这类内置管道属于CommonModule,你需要手动将该模块导入到组件的imports数组中。

修改heroes.component.ts文件,添加CommonModule的导入并加入到组件配置的imports里:

import { Component } from '@angular/core';
import { Hero } from '../hero';
// 导入包含内置管道的CommonModule
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-heroes',
  standalone: true,
  // 将CommonModule添加到imports数组
  imports: [CommonModule],
  templateUrl: './heroes.component.html',
  styleUrl: './heroes.component.css'
})
export class HeroesComponent {
  hero : Hero={
    id:1,
    name :'Windstorm'
  };
}

所有Angular内置的通用管道(如lowercase、date、currency等)、指令(如*ngIf、*ngFor)都封装在CommonModule中,独立组件使用这些特性时,都需要显式导入该模块。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 04:02:06