Core: Update Ionic 2 example to RC.0

Created on 28 Sep 2016  路  13Comments  路  Source: ngx-translate/core

Current behavior

Readme explains bootstrapping for Ionic Beta

Expected/desired behavior

Readme explains bootstrapping for Ionic RC

Edit: Trying to put TranslateModule.forRoot() into imports in _app.module.ts_ will kill the _ngc_.

medium TODO docs

Most helpful comment

On my side it writes:
[16:58:58] Error: Module /node_modules/ng2-translate/ng2-translate.js does not export TranslateLoader (imported by /.tmp/app/app.module.js)

I did the following in app.model.ts:

import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate/ng2-translate';
imports: [
    BrowserModule,
    HttpModule,
    TranslateModule.forRoot({
        provide: TranslateLoader,
        useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
        deps: [Http]
    }),
    IonicModule.forRoot(MyApp)
],
exports: [BrowserModule, HttpModule, TranslateModule],

All 13 comments

Yes, it's definitely on my todo list :)

Any quick tips on how to get it to work with Ionic RC.0?

I suppose it should work just like the regular documentation for non ionic apps, just import the module and call forRoot() (with or without parameters, depending on what you need, check for the readme for that)

Unfortunately it doesn't work. I get
ngc error: Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in xxx/.tmp/app/app.module.ts, resolving symbol AppModule in xxx/.tmp/app/app.module.ts

Using
imports: [ IonicModule.forRoot(MyApp), HttpModule, TranslateModule.forRoot() ],

Hi! That's #218 .

Ah, so it is. Thank you.

On my side it writes:
[16:58:58] Error: Module /node_modules/ng2-translate/ng2-translate.js does not export TranslateLoader (imported by /.tmp/app/app.module.js)

I did the following in app.model.ts:

import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate/ng2-translate';
imports: [
    BrowserModule,
    HttpModule,
    TranslateModule.forRoot({
        provide: TranslateLoader,
        useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
        deps: [Http]
    }),
    IonicModule.forRoot(MyApp)
],
exports: [BrowserModule, HttpModule, TranslateModule],

TranslateLoader and TranslateStaticLoader can be imported from 'ng2-translate/src/translate.service', but calling TranslateModule.forRoot() will cause the build process to fail.

dev mode works fine if we include {TranslateLoader , TranslateStaticLoader, TranslateService } from 'ng2-translate/src/translate.service',

"ionic build" fails

ngc error: Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 30:23 in the original .ts file), resolving symbol AppModule in C:/Users/dsc/dev/23_angular__rhenus__information/.tmp/app/app.module.ts at simplifyInContext (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\static_reflector.js:469:23) at StaticReflector.simplify (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\static_reflector.js:472:22) at StaticReflector.annotations (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\static_reflector.js:61:36) at _loop_1 (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\codegen.js:53:54) at CodeGenerator.readFileMetadata (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\codegen.js:66:13) at C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\codegen.js:100:74 at Array.map (native) at CodeGenerator.codegen (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\codegen.js:100:35) at codegen (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\compiler-cli\src\main.js:7:81) at Object.main (C:\Users\dsc\dev\23_angular__rhenus__information\node_modules\@angular\tsc-wrapped\src\main.js:30:16)

Same for me.

Error: Module node_modules/ng2-translate/ng2-translate.js does not export TranslateLoader (imported by /home/SideMenu/.tmp/app/app.module.js)

Thanks for the quick fix!

Be careful, for ionic the configuration should be :
useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
instead of
useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),

(mind the slash before assets)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crebuh picture crebuh  路  3Comments

IterationCorp picture IterationCorp  路  3Comments

apreg picture apreg  路  3Comments

dankerk picture dankerk  路  3Comments

Snap252 picture Snap252  路  3Comments