在 Angular JS 中解码 HTML 实体 [英] Decode HTML entity in Angular JS

查看:22
本文介绍了在 Angular JS 中解码 HTML 实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 angular JS 解码文本中的 HTML 实体.

How do i decode HTML entity in text using angular JS.

我有字符串

""12.10 On-Going Submission of ""Made Up"" Samples.""

我需要一种使用 Angular JS 对其进行解码的方法.我找到了一种使用 javascript 此处 来做到这一点的方法,但我确信这不适用于 Angular.需要在 UI 上取回原始字符串,看起来像

I need a way to decode this using Angular JS. I found a way to do that using javascript here but I am sure thats wont work for Angular. Need to get back the original string on the UI which would look like

""12.10 On-Going Submission of ""Made Up"" Samples.""

推荐答案

您可以使用 ng-bind-html 指令将其显示为 html 内容,其中所有 html 实体都已解码.只需确保在您的应用程序中包含 ngSanitize 依赖项即可.

You can use the ng-bind-html directive to display it as an html content with all the html entities decoded. Just make sure to include the ngSanitize dependency in your application.

演示

JAVASCRIPT

angular.module('app', ['ngSanitize'])

  .controller('Ctrl', function($scope) {
    $scope.html = '"12.10 On-Going Submission of ""Made Up"" Samples."';
  });

HTML

  <body ng-controller="Ctrl">
    <div ng-bind-html="html"></div>
  </body>

这篇关于在 Angular JS 中解码 HTML 实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆