我试图在我的页面上执行更改语言的功能,但我收到此错误:
财产'翻译'类型' LogComponent'
上不存在export class LogComponent {
langs: any;
constructor( translate: TranslateService ){
this.langs = translate.getLangs();
}
langSelect(lang: string): void {
this.translate.use(lang);
}
}
和我的HTML:
<select #langSelected (change)="langSelect(langSelected)">
<option *ngFor="let l of langs" [value]="l">{{ l }}</option>
</select>
这不起作用......我错过了什么吗?
答案 0 :(得分:1)
translate
不存在,因为您从未将其定义为变量。尝试更改
constructor( translate: TranslateService ){
到
constructor( private translate: TranslateService ){
在构造函数定义中放置public
,private
,protected
等是将其定义为类变量的简写,如下所示:
export class LogComponent {
private translate: TranslateService;
constructor( translate: TranslateService ){
this.translate = translate;
}
}