2017-09-02 98 views
1

嗨大膽的特定部分,我有如下的HTML代碼:使用ngTranslate翻譯說明如何使一個字符串角2

<div class="row"> 
     <div class="col-12" style="margin-top:15px;margin-bottom:10px"> 
      {{"description" | translate}} 
     </div> 
</div> 

上午。描述是我的翻譯文件中的一個鍵,並且鍵的值將顯示。說明如下:「點擊取消取消或點擊確認繼續」。我想先取消並在說明中確認爲粗體。我怎樣才能做到這一點使用CSS和角2?任何想法的傢伙?提前致謝。

回答

5

你應該利用[innerHTML],具有HTML標記您的翻譯中是這樣的:

{ 
    "description": "click <strong>cancel</strong> to cancel or click <strong>confirm</strong> to proceed" 
} 

而且在模板綁定爲HTML字符串:

<div [innerHTML]="'description' | translate"></div> 

請檢查Official Documentation

更新Working Plunker Example

+0

試過了。但標籤正在顯示。沒有使它成爲一個文本本身的強大文本 – blackdaemon

+0

。不知道爲什麼 – blackdaemon

+0

@blackdaemon真的!您正在使用的角度版本(&顛覆)? – Shantanu

-2

在使用translate時,您必須拆分文本以使Angular 2中的字符串的特定部分變爲粗體。

像這樣: http://jsfiddle.net/Eh2ym/

<span>before slash/after slash</span><br> 
<span>before slash/after slash</span><br> 
<script> 
$('span').html(function(i, old){ 
    var htm= old.split('/'); 
    return '<strong>'+ htm[0] +'</strong>'+htm[1];  
}) 
<script> 

但上面的例子是在JavaScript。