如何显示角度JS在HTML XML文本 [英] How to display xml text in html in angular js

查看:87
本文介绍了如何显示角度JS在HTML XML文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据字符串 -

I have some data in string -

 var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel>    </rss>" ;

现在我想这个字符串是在正确的XML格式的网页上显示的。

Now I want this string to be display on web page in proper xml format .

<channel>
   <title>
        RSS Title
   </title>
</channel>

我怎样才能做到这一点?

How can I do this?

推荐答案

期待google- code-prettify会做工作,但看起来没有做缩进。随着压痕(vkbeautify)提供额外的插件能够得到缩进正确的XML格式。

Was expecting google-code-prettify would do the job but looks like it does not do indentation. With an additional plugin for indentation (vkbeautify) able to get the proper xml format with indentation.

http://plnkr.co/edit/Pep9HurLI8NPtAXRsoFD?p=$p$ PVIEW

<div ng-controller="myCtrl">
  <pre class="prettyprint lang-xml"></pre>
</div>

App.directive('prettyprint', function() {
  return {
    restrict: 'C',
    link: function postLink(scope, element, attrs) {
          element.text(vkbeautify.xml(scope.dom, 4));
    }
  };
});

这篇关于如何显示角度JS在HTML XML文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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