我正在使用locale注入,并且我能够将它注入到构造函数中,我想知道是否可以将它作为属性注入。这将带我到我的下一个问题,我能注入一个简单的模型吗。我正在使用
class-transformer
export class AppComponent implements OnInit {
@Inject(LOCALE_ID) public localeProperty: string;
constructor(@Inject(LOCALE_ID) public locale: string, public appService: AppService) {
}
ngOnInit() {
console.log('AppComponent.locale: ', this.locale);
console.log('AppComponent.localeProperty: ', this.localeProperty);
AppComponent.locale:法语
AppComponent.localeProperty:未定义
在我的位置模型中,我希望模型知道要使用什么标签,理想情况下,我希望能够注入LOCALE\u ID
import {locale} from '../../environments/locale';
export class Location {
enLabel: string;
frLabel: string;
// can i do something here
constructor() {
}
get label() {
return this[`${locale}Label`] ? this[`${locale}Label`] : this.enLabel;
}
我是吉特
https://github.com/ricardosaracino/class-transformer