0

I want translate a text , I always use {{ 'Name' | translate }} in my html But now I need use translate en my .ts but I have a problem.

 this.gridOptions = <GridOptions>{}; this.columnDefs = [ { headerName: {{'Name' | translate }}, field: 'name' }]; Forbbiden bitwise operation (no-bitwise) Not found the name translate hope ','. hope ';'. 

Thanks

2 Answers 2

2

You could use ngx-translate for this.

constructor(private translate: TranslateService) { this.translate.setDefaultLang('en'); // Initially setting the language as the browser's lang if (this.translate.getBrowserLang() !== undefined) { this.translate.use(this.translate.getBrowserLang()); } else { this.translate.use('en'); } } generateColDef() { // 'APP.NAMESTR' is the key to your Names translation which resides in your language json this.translate.get('APP.NAMESTR').subscribe(value => { this.columnDefs = [{ headerName: value, field: 'name' }]; }); } 

For a more complete example checkout this stackblitz

Sign up to request clarification or add additional context in comments.

Comments

1

You have to use Pipe in .ts file like this:

import {Pipename} from './pipename'; Pipename.prototype.transform(arguments); 

No need to use {{}} in .ts file.

1 Comment

I can do with translate.get('Name').subscribe(value => { this.Name = value; } )? Y prefer dont use Pipename in .ts

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.