Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngx-translate innerHTML styling

I using Angular 5.0.1 and ngx-translate/core 8.0.0

I have this code in template

<p [innerHTML]="'privacyAgree'|translate:{href:'#'}"></p>

and this string in en.json

"privacyAgree": "Clicking «Registration» button, I accept<a href=\"{{href}}\">the terms</a>"

and this code in my less file

p{
    color: #8A8C8D;
    font-size: 13px;
    line-height: 1.4em;
    a{
        color: #222222;
    }
}

but color for inner "a" will not apply because Angular create this styles

p[_ngcontent-c3] {
  color: #8A8C8D;
  font-size: 13px;
  line-height: 1.4em;
}
p[_ngcontent-c3]   a[_ngcontent-c3] {
  color: #222222;
}

but ngx-translate create this code

<p _ngcontent-c3="">Clicking «Registration» button, I accept<a href="#">the terms</a></p>

and "a" tag doesn't have necessary attribute.

So how I can render [innerHTML] template after translation?

like image 991
Ruslan Avatar asked Nov 21 '17 13:11

Ruslan


People also ask

How to use ngx translate in Angular?

Setting Up the Project Create a brand new Angular application and add some dependencies. Open your terminal and use @angular/cli to create a new project: ng new angular-ngx-translate-example --skip-tests.

Is Ngx translate dead?

No sadly not anymore.

What is translate pipe in angular?

The service also contains a method called translate. It is later called by the pipe to get the translation for a specific key. It always uses the language specified in the 'language'-variable of the service, to lookup the translation. That's it.


1 Answers

You have to change Encapsulation mode of your component.

Check this question, it had similar problem.

Encapsulation

like image 91
Bunyamin Coskuner Avatar answered Oct 11 '22 21:10

Bunyamin Coskuner