My code is causing an error during compilation:
export class NoticeService {
public notice: Observable<any>;
private observer: any;
constructor(private translate: TranslateService) {
this.notice = new Observable(observer => {
this.observer = observer;
}).share();
}
create(value: string) {
let translatedValue = this.translate.get(value).value;
this.observer.next(translatedValue);
}
}
The result of
console.log(this.translate.get(value))
is:
ScalarObservable {_isScalar: true, value: "Some proper value!", etc.
The output of console.log(translatedValue)
shows:
"Some proper value!"
An error message states:
ERROR in [default] /somePath/notice.service.ts:21:52
Property 'value' does not exist on type 'Observable<any>'.
The issue seems to be with line 21:
let translatedValue = this.translate.get(value).value;
Can you spot the problem?
Update:
I am using ng2-translate and here is the implementation of the get
method:
/**
* Gets the translated value of a key (or an array of keys)
* @param key
* @param interpolateParams
* @returns {any} the translated key, or an object of translated keys
*/
TranslateService.prototype.get = function (key, interpolateParams) {
var _this = this;
if (!key) {
throw new Error('Parameter "key" required');
}
// check if we are loading a new translation to use
if (this.pending) {
return this.pending.map(function (res) {
return _this.getParsedResult(_this.parser.flattenObject(res), key, interpolateParams);
});
}
else {
var translations = void 0;
if (this.translations[this.currentLang]) {
translations = this.parser.flattenObject(this.translations[this.currentLang]);
}
return Observable_1.Observable.of(this.getParsedResult(translations, key, interpolateParams));
}
};