【问题标题】:Angular 7 doesn't find pipesAngular 7 找不到管道
【发布时间】:2019-04-29 10:23:20
【问题描述】:

我正在尝试构建我的 Angular 7 项目,但每次我收到一个错误提示

模板解析错误:找不到管道“货币”。

但是当我尝试运行 ng serve 时,它确实按预期工作

我尝试使用--prod 标志构建它,但它不起作用。如果我删除生产标志,它会正确构建。

【问题讨论】:

  • 您是否将管道添加到您正在使用它的模块的declarations/export
  • This question 可以帮到你。
  • 其实我找到了解决这个问题的另一种方法,AOT 有问题,我不得不禁用 AOT 并使用标志 --prod --aot false --build-optimizer false 构建优化器,它工作了
  • 这不是真正的解决方案。您看到此错误的事实一定意味着管道的导入有问题。

标签: javascript angular web angular7 angular-pipe


【解决方案1】:

试试这个: 在tsconfig.json

"angularCompilerOptions": {
    "enableIvy": true
}

"angularCompilerOptions": {
    "enableIvy": false
}

【讨论】:

  • 纯代码答案没有太大帮助,请解释为什么它会起作用。
【解决方案2】:

为了使用管道,你首先需要在你的模块声明中添加管道:

import {CurrencyPipeComponent}  from './currencypipe.component';

@NgModule({
  imports:      ...,
  declarations: [
                 ...,
                 CurrencyPipeComponent],
})
export class YourModuleWhichYourComponentIsRegistered { } 

【讨论】:

    猜你喜欢
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2019-01-06
    • 2017-03-25
    • 2020-09-21
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多