离子,找不到管道 'translate',仅在 AoT 编译器中
Ionic, The pipe 'translate' could not be found, only in AoT Compiler
当我尝试构建生产版本时,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
- Angular: 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 的提示,但这两个更改都没有解决我的问题。如何配置翻译模块以使其在生产版本中运行?
好的,解决了。我在页面class中添加了TranslateModule的导入和导出语句,但正确的是将其添加到相应的模块中。
在我的例子中:
错误:
contact.ts
@NgModule({
imports: [
TranslateModule
],
exports: [
TranslateModule
]
})
export class ContactsPage {...}
正确:
contact.module.ts
@NgModule( {
...
imports : [
...
TranslateModule
],
exports : [
TranslateModule
]
} )
export class ContactsPageModule {
}
当我尝试构建生产版本时,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
- Angular: 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 的提示,但这两个更改都没有解决我的问题。如何配置翻译模块以使其在生产版本中运行?
好的,解决了。我在页面class中添加了TranslateModule的导入和导出语句,但正确的是将其添加到相应的模块中。
在我的例子中:
错误:
contact.ts
@NgModule({
imports: [
TranslateModule
],
exports: [
TranslateModule
]
})
export class ContactsPage {...}
正确:
contact.module.ts
@NgModule( {
...
imports : [
...
TranslateModule
],
exports : [
TranslateModule
]
} )
export class ContactsPageModule {
}