2017-09-02 92 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。