【问题标题】:How to interpretHTML code inside uib-tooltip如何在 uib-tooltip 中解释 HTML 代码
【发布时间】:2017-01-19 13:28:05
【问题描述】:

在寻找解决方案后,我发现了很多文章,但没有一种方法可以做我想做的事,所以我就在那里。

我的问题: 我使用 uib-tooltip 对某些字段的使用/效用进行了一些解释。我还将 $translate 与 i18n 文件一起使用来进行一些翻译。 这些 i18n 文件包含一些特殊字符的 html 代码(由于服务器问题,我不能简单地使用 UTF-8...)。

因此,当我仅用于示例时:

<span translate="create.period"></span>

它工作正常,HTML 被解释得很好,我得到了很好的结果。 我的 i18n 文件的价值示例:

create.period:'Ce champ contient la valeur de la p&eacute;riode'

之前代码的结果:

Ce champ contient la valeur de la période

但如果我使用 uib-tooltip 我会遇到一些问题。 我的代码示例:

<span class='glyphicon glyphicon-question-sign pointer signColor' uib-tooltip="{{'create.period' | translate}}"></span>

工具提示弹出窗口的结果是:

Ce champ contient la valeur de la p&eacute;riode

我见过很多东西,比如旧方法 (uib-tooltip-html) 或方法 $sce 和 ng-bind-html,但我不能在这里这样做,因为我在 uib-tooltip 上。

所以我错过了一些简单的事情吗? 或者你有我的解决方案吗? (和解释:p)

非常感谢! :)

我尝试添加一个过滤器:

filter("htmlToPlaintext",  ['$sce', '$compile', function ($sce, $compile) {
return function (val) {
    return $sce.valueOf($sce.trustAsHtml(val));;
};

}])

可惜没用。

【问题讨论】:

  • 你好用这个uib-tooltip-html
  • 正如我所说,我已经看到了,但这不起作用,它总是显示 html 代码而不是解释的字符:S
  • 你可以尝试使用$translateProvider.useSanitizeValueStrategy(null);
  • 嗨,很遗憾,这不起作用,我已经尝试过了(以及此清理策略的所有可能价值)。 :S

标签: html angularjs translate


【解决方案1】:
$scope.create.period = $sce.trustAsHtml('Ce champ contient la valeur de la p&eacute;riode');

<a href="#" uib-tooltip-html="create.period">scope variable</a>
<span class='glyphicon glyphicon-question-sign pointer signColor' uib-tooltip-html="create.period"></span>

在您的控制器中传递“$sce”依赖项

【讨论】:

  • 如果它有效,我不知道,但这个解决方案的问题是,对于我的翻译文件的每个键,我必须用你的解决方案在控制器上创建一个 var,这很重(我有一些带有大表单和每个字段的工具提示的页面,这样做会产生大量的键)。但是我尝试使用使用 $sce.trustAsHtml 的过滤器来过滤我的结果,但这不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
  • 2011-04-14
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多