本文介绍了注射" NG-按一下[在HTML与ngSanitize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有角的定位,我坚持了最后一件事情在这里。

I'm working on localization with Angular and I'm stuck with one last thing here.

我有这样的json一滴

I have this json blob

  {
    "key": "_need_to_login_",
    "value": "You need to <a ng-click=\"login()\">log in</a> to add an event.",
    "description": "Banner alert info tell user to login before they can add an event"
  }

所以用这个模块,我将能够做到这一点。

So with this Angular i18n module I will be able to do this

{{ "_need_to_login_" | i18n }}

问题是,它包含了一些标记在那里,它会简单转义,并会显示此页

The problem is that it contains some markup in there and it will simple escape it and will display this on the page

You need to <a ng-click="login()">log in</a> to add an event.

但随着我能反转义的标记和显示它正确的:

But with ngSanitize I'm able to unescape that markup and display it correctly as:

您需要添加事件。

但我没有这样的 NG-点击插入为好。

But I don't have that ng-click inserted as well.

尝试复制并在这里进行测试:的sanitize $

Try copy that and test it here : http://docs.angularjs.org/api/ngSanitize/service/$sanitize

我的问题是,我怎么可以插入 NG-点击从注入code以及UNESCAPE字符串?

My question is that how can I insert ng-click from the injected code as well as unescape the string?

推荐答案

NG绑定,HTML应该做你想要什么。让我知道它是如何工作的,我们计划很快添加翻译支持我们的应用程序。

ng-bind-html should do what you want. Let me know how it works out, we are planning to add translation support soon to our app.

EDIT2:请不要介意有关的jsfiddle编辑。它没有工作。

nevermind about the jsfiddle edit. It didnt work.

这篇关于注射&QUOT; NG-按一下[在HTML与ngSanitize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 22:51