Skip to content

Commit

Permalink
fix(TranslateService): update to Angular 2 beta 0 and avoid Expressio…
Browse files Browse the repository at this point in the history
…nChangedAfterItHasBeenCheckedEx
  • Loading branch information
ocombe committed Dec 15, 2015
1 parent 8fe8c6c commit e9dd9e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion src/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class TranslateService {
private pending: any;
private translations: any = {};
private defaultLang: string = 'en';
private langs: Array<string>;
private parser: Parser = new Parser();

constructor(private http: Http) {
Expand Down Expand Up @@ -119,6 +120,7 @@ export class TranslateService {

this.pending.subscribe((res: Object) => {
this.translations[lang] = res;
this.updateLangs();
this.pending = undefined;
});

Expand All @@ -132,14 +134,22 @@ export class TranslateService {
*/
public setTranslation(lang: string, translations: Object) {
this.translations[lang] = translations;
this.updateLangs();
}

/**
* Returns an array of currently available langs
* @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);
}

/**
Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": true
"declaration": true,
"moduleResolution": "node"
},
"files": [
"ng2-translate.ts"
],
"exclude": [
"node_modules"
]
Expand Down

0 comments on commit e9dd9e0

Please sign in to comment.