Last active
May 13, 2016 15:13
-
-
Save gaetancollaud/777f519d551cc35ce60073e902e17a7e to your computer and use it in GitHub Desktop.
Angular2 translate component/directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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