【问题标题】:Ionic, The pipe 'translate' could not be found, only in AoT Compiler离子,无法找到管道“翻译”,仅在 AoT 编译器中
【发布时间】:2018-10-24 09:02:45
【问题描述】:

当我尝试构建生产版本时,我在 Ionic 应用程序中遇到了 ngx-translate 问题。

在开发过程中,翻译工作正常

ionic serve

和

ionic cordova build android

但如果我尝试使用

进行生产构建
ionic cordova build android --prod --release

或用于 PWA

ionic build --prod

我收到一些错误,例如

[17:47:15]  typescript error 
            The pipe 'translate' could not be found ( ... )

版本:

  • ngx 翻译:8.0.0
  • 离子:3.9.2
  • 角度:5.2.10

我检查过:https://github.com/ngx-translate/core/tree/v8.0.0,但找不到我做错了什么。

在 app.module 中:

// https://github.com/ngx-translate/core#1-import-the-translatemodule
// AoT requires an exported function for factories
export function createTranslateLoader(http: Http) {
    return new TranslateHttpLoader( http, './assets/i18n/', '.json' );
} 

@NgModule( {
    ...
    imports: [
        ...
        TranslateModule.forRoot( {
                loader: {
                    provide: TranslateLoader,
                    useFactory: (createTranslateLoader),
                    deps: [ Http ]
                }
            }
        ),
        ...

在我的一个产生此错误的页面中:

import {  TranslateModule, TranslateService, TranslatePipe } from '@ngx-translate/core';

@NgModule({
    imports: [
        TranslateModule
    ],
    exports: [
        TranslateModule
    ]
})
export class ContactPage { ... }

通过 SO 搜索主要产生了在页面中导入和导出 TranslateModule 以及导入 TranslatePipe 的提示,但是这两个更改都没有解决我的问题。如何配置翻译模块以使其在生产版本中工作?

【问题讨论】:

    标签: ionic-framework ngx-translate


    【解决方案1】:

    好的,解决了。我在页面类中添加了TranslateModule的导入导出语句,正确的是添加到对应的模块中。

    在我的例子中:

    错误:

    contact.ts

    @NgModule({
        imports: [
            TranslateModule
        ],
        exports: [
            TranslateModule
        ]
    })
    export class ContactsPage {...}
    

    正确:

    contact.module.ts

    @NgModule( {
        ...
        imports : [
            ...
            TranslateModule
        ],
        exports : [
            TranslateModule
        ]
    
    } )
    export class ContactsPageModule {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 1970-01-01
      • 2020-01-10
      • 2013-01-15
      • 2012-10-21
      • 2012-12-19
      相关资源
      最近更新 更多