From e9dd9e0419f492639f92eb9ec6813dee6c93e0be Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Tue, 15 Dec 2015 23:07:37 +0100 Subject: [PATCH] fix(TranslateService): update to Angular 2 beta 0 and avoid ExpressionChangedAfterItHasBeenCheckedEx --- package.json | 7 +++---- src/translate.service.ts | 13 ++++++++++++- tsconfig.json | 6 +++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b2b14665..7aecc185 100644 --- a/package.json +++ b/package.json @@ -26,17 +26,16 @@ "typings": "./ng2-translate.d.ts", "homepage": "https://github.com/ocombe/ng2-translate", "dependencies": { - "angular2": "2.0.0-alpha.53", + "angular2": "~2.0.0-beta.0", "es6-promise": "^3.0.2", "es6-shim": "^0.33.3", "reflect-metadata": "0.1.2", - "rxjs": "5.0.0-alpha.14", - "zone.js": "0.5.8" + "rxjs": "5.0.0-beta.0", + "zone.js": "~0.5.10" }, "devDependencies": { "commitizen": "~2.4.6", "cz-conventional-changelog": "~1.1.4", - "es6-shim": "~0.33.13", "jasmine-core": "~2.3.4", "karma": "~0.13.15", "karma-chrome-launcher": "~0.2.2", diff --git a/src/translate.service.ts b/src/translate.service.ts index b0e423b4..daa335c1 100644 --- a/src/translate.service.ts +++ b/src/translate.service.ts @@ -65,6 +65,7 @@ export class TranslateService { private pending: any; private translations: any = {}; private defaultLang: string = 'en'; + private langs: Array; private parser: Parser = new Parser(); constructor(private http: Http) { @@ -119,6 +120,7 @@ export class TranslateService { this.pending.subscribe((res: Object) => { this.translations[lang] = res; + this.updateLangs(); this.pending = undefined; }); @@ -132,6 +134,7 @@ export class TranslateService { */ public setTranslation(lang: string, translations: Object) { this.translations[lang] = translations; + this.updateLangs(); } /** @@ -139,7 +142,14 @@ export class TranslateService { * @returns {any} */ public getLangs() { - return Object.keys(this.translations); + return this.langs; + } + + /** + * Update the list of available langs + */ + private updateLangs() { + this.langs = Object.keys(this.translations); } /** @@ -166,6 +176,7 @@ export class TranslateService { */ public set(key: string, value: string, lang: string = this.currentLang) { this.translations[lang][key] = value; + this.updateLangs(); } private changeLang(lang: string) { diff --git a/tsconfig.json b/tsconfig.json index d8807ba4..62e68c18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,8 +6,12 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, - "declaration": true + "declaration": true, + "moduleResolution": "node" }, + "files": [ + "ng2-translate.ts" + ], "exclude": [ "node_modules" ]