Skip to content

Commit

Permalink
fix(directive): always refresh value when directive params change
Browse files Browse the repository at this point in the history
Fixes #423
  • Loading branch information
ocombe committed Mar 23, 2017
1 parent c27e277 commit c2c06bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/translate.directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Directive, ElementRef, AfterViewChecked, Input, OnDestroy, ChangeDetectorRef} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {isDefined} from './util';
import {equals, isDefined} from './util';
import {TranslateService, LangChangeEvent} from './translate.service';
import {TranslationChangeEvent} from "./translate.service";
import {DefaultLangChangeEvent} from "./translate.service";
Expand All @@ -24,9 +24,9 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
}

@Input() set translateParams(params: any) {
if(this.currentParams !== params) {
if(!equals(this.currentParams, params)) {
this.currentParams = params;
this.checkNodes();
this.checkNodes(true);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/translate.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,18 @@ describe('TranslateDirective', () => {
it('should update the translation when params change', () => {
// replace the content with the key
expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual('TEST');
expect(fixture.componentInstance.withParamsNoKey.nativeElement.innerHTML).toEqual('TEST');

translate.setTranslation('en', {"TEST": "It is {{value}}"});
translate.use('en');

expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual('It is ok');
expect(fixture.componentInstance.withParamsNoKey.nativeElement.innerHTML).toEqual('It is ok');
fixture.componentInstance.value = {value: 'changed'};
fixture.detectChanges();

expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual('It is changed');
expect(fixture.componentInstance.withParamsNoKey.nativeElement.innerHTML).toEqual('It is changed');
});

it('should update the DOM when the lang changes', () => {
Expand Down

0 comments on commit c2c06bc

Please sign in to comment.