angular - 请添加@Pipe/@Directive/@Component注解IONIC 3

标签 angular typescript ionic-framework ionic3

这在作为开发运行时可以正常工作,但是当您将命令运行到生产环境时出现以下错误:

工作:

ionic cordova run android

不工作:

ionic cordova run android --prod --release

错误:

    [03:34:41]  typescript error
                Unexpected module 'TranslateModule in C:/Users/tm_ma/Doc/PROJECT/node_modules/@ngx-translate/core/core.d.ts' declared by the module 'EmentaPageModule in
                C:/Users/tm_ma/Doc/PROJECT/src/pages/ementa/ementa.module.ts'. Please add a
                @Pipe/@Directive/@Component annotation.
  [03:34:41]  ionic-app-script task: "build"
  [03:34:41]  Error: The Angular AoT build failed. See the issues above
    Error: The Angular AoT build failed. See the issues above

EMENTA 模块:

import { NgModule, Component } from '@angular/core'; 
import { IonicPageModule } from 'ionic-angular'; 
import { EmentaPage } from './ementa'; import { TranslateModule } from '@ngx-translate/core';


@NgModule({  
   declarations: [
    EmentaPage,
    TranslateModule
       ],   imports: [
    IonicPageModule.forChild(EmentaPage),
    TranslateModule
       ], }) export class EmentaPageModule {}

应用模块:

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

@NgModule({
  declarations: [
   ...
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    })

  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
   ...
  ],
  providers: [

  ]
})
export class AppModule {}

版本:

"@ngx-translate/core": "^9.1.1",
"@ngx-translate/http-loader": "^4.0.0",   
"angularfire2": "^5.0.0-rc.11",   
"@angular/animations": "5.2.11",    
"@angular/common": "5.2.11",    
"@angular/compiler": "5.2.11",   
"@angular/compiler-cli": "5.2.11",    
"@angular/core": "5.2.11",    
"@angular/forms": "5.2.11",   
"@angular/http": "5.2.11",

最佳答案

Angular5 应该使用 core 8.x - 9.x 和 loader 1.x - 2.x Angular4.3 应该使用 core 7.x 或更少和 loader 1.x - 2.x

那里有详细信息https://github.com/ngx-translate/core

我的应用程序使用 ionic4 (angular6) 并且 ngx-translate 对我来说没问题(core 10.x 和 loader 3.x)

关于angular - 请添加@Pipe/@Directive/@Component注解IONIC 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53423673/

相关文章:

angular - Ionic 4字符串到html

Angular 2 : How to conditionally load a Component in a Route asynchronously?

javascript - 捕获第一个视频帧

javascript - 如何获取经过身份验证的用户的数据/id?

node.js - ionic CLI : all commands giving error undefined:1 SyntaxError: Unexpected token

组件中的Angular 2重复订阅

angular - 清除按钮未重置 Angular 6 下拉列表中的选定值

reactjs - react typescript : Type 'null' is not assignable to type 'CanvasRenderingContext2D'

typescript - 是否有 CDK 或 CloudFormation 构造来导入整个 DNS 区域传输?

Angular 6 - 生命周期 Hook 中的 promise 使其他测试失败