I'm trying to do a really simple translate pipe for angular2. But I might be wrong how to promise work. The idea is to get the language parameter from a async service which call a doc in PouchDB. Fyi, the data are organised like this:
{
title: {
fr: "text in french",
en : "text in english",
...
}
The retu inside the promise doesn't work. The html template is empty. I don't get why.
@Pipe({name: 'translate'})
export class Translate {
lang:any;
constructor(private interfaceService: Interface){}
transform(obj) {
this.interfaceService.getParams().then((data) => {
retu obj[data.language]
}).catch((error) => {
console.log(error);
});
}
}
If I put the retu outside of the promise, it works:
@Pipe({name: 'translate'})
export class Translate {
lang:any;
constructor(private interfaceService: Interface){}
transform(obj) {
retu obj.en
}
}
Thanks for your help
