question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with TranslateService in Pipe

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior I’m creating a new pipe that uses translate service inside. Code below:

export class TimeRemainingPipe implements PipeTransform {
    constructor(private translateService: TranslateService) {}
    transform(input: any, args?: any): any {
        return this.translateService.get('TEST').subscribe(res => res);
    }
}

When I use that pipe in the template, what I got is always [object] string. I think the problem is observable/subscriber but I don’t know how to solve it.

Please help! Thank you very much.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
phatpham9commented, Mar 29, 2017

problem solved. the code is below

@Pipe({
    name: 'timeRemaining',
    pure: false
})
export class TimeRemainingPipe implements PipeTransform {
    private result;

    constructor(private translateService: TranslateService) {}

    transform(input: any, args?: any): any {
        this.translateService.get('TEST').subscribe(res => this.result = res);
        return this.result;
    }
}

any thanks @NKjoep 😃

0reactions
phatpham9commented, Mar 29, 2017

Sorry @NKjoep I didn’t see your edit in the previous comment. I just tried and the output still the same.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR in : The pipe 'translate' could not be found
I can see that the TranslateService works fine as it properly translate and output to the console successfully, however the pipe nor the...
Read more >
How to unit test a component with TranslateService ... - GitHub
Question How to test a component that uses TranslateService and the translate pipe? I have a root module with: TranslateModule.
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
How To Use ngx-translate with Angular - DigitalOcean
Using TranslateService. Using the service, there are two methods to get your translations. The first, and recommended, method is to use:.
Read more >
Translate your Angular App with Pipes - malcoded
Translating you app to other languages is a pretty common task. Unfortunately it can be a very frustrating and boring topic.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found