Skip to content

Instantly share code, notes, and snippets.

@gaetancollaud
Last active May 13, 2016 15:13
Show Gist options
  • Save gaetancollaud/777f519d551cc35ce60073e902e17a7e to your computer and use it in GitHub Desktop.
Save gaetancollaud/777f519d551cc35ce60073e902e17a7e to your computer and use it in GitHub Desktop.
Angular2 translate component/directive
import {Directive, ElementRef, Input} from "angular2/core";
import {TranslateService} from "ng2-translate";
@Directive({
selector: '[translate]'
})
export class Translate {
constructor(private translateService:TranslateService, private element:ElementRef) {
}
@Input('translate')
set translate(key:string) {
let self = this;
this.translateService.get(key).subscribe(value => this.element.nativeElement.innerHTML = value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment