Angular 角度11.0.4罐';我找不到烟斗
我正试图使用管道根据应用程序中的下拉选择突出显示某些文本,我在应用程序模块中声明了管道模块,并注册为我要在其中使用它的组件的提供商,但我收到一个错误,说找不到名称为的管道。下面是相关代码以及我如何尝试使用它。我的管道申报不正确还是登记不正确 突出显示text.pipe.ts取自 page.component.tsAngular 角度11.0.4罐';我找不到烟斗,angular,Angular,我正试图使用管道根据应用程序中的下拉选择突出显示某些文本,我在应用程序模块中声明了管道模块,并注册为我要在其中使用它的组件的提供商,但我收到一个错误,说找不到名称为的管道。下面是相关代码以及我如何尝试使用它。我的管道申报不正确还是登记不正确 突出显示text.pipe.ts取自 page.component.ts @NgModule({ declarations: [ {other declarations}, HighlightTextPipe ], import {
@NgModule({
declarations: [
{other declarations},
HighlightTextPipe
],
import {HighlightTextPipe} from '../../pipes/highlight-text.pipe';
@Component({
{other declarations}
providers: [HighlightTextPipe]
})
如何在page.component.html中使用它:
<span>{{ text | highlightText : 'Annex'}}</span>
{{text | highlightText:'附件'}
我得到的错误是:
Error: src/app/components/page.component.html:89:69 - error NG8004: No pipe found with name 'highlightText'.
89 <span>{{text | highlightText : 'Annex'}}</span>
错误:src/app/components/page.component.html:89:69-错误NG8004:未找到名为“highlightText”的管道。
89{{text | highlightText:'附件}
管道实际上并不是真正的提供者。如果在模块上定义它,则必须将其放入声明:[……]
部分
话虽如此,组件没有声明
部分
因此,这意味着您不能在组件上声明管道。但是,您可以在模块上声明它,这将使该模块中的所有组件都可以使用它。(见讨论:)
(但是,如果您确实希望将范围限制为一个组件,那么您当然可以为该特定组件创建一个模块。)这为我解决了问题,谢谢!对于任何有类似问题的人,为所有应该具有管道工程的组件使用共享模块(对于我来说,需要它的组件实际上并不是我发现的应用程序模块的一部分)
Error: src/app/components/page.component.html:89:69 - error NG8004: No pipe found with name 'highlightText'.
89 <span>{{text | highlightText : 'Annex'}}</span>