خرید بک لینک

Vote count: 0

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

asked 1 min ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 22 تير 1395 ساعت: 17:56

صفحه بندی