如何在angular js的html中显示xml文本 [英] How to display xml text in html in angular js
问题描述
我有一些字符串数据 -
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel> </rss>";
现在我希望这个字符串以正确的 xml 格式显示在网页上.
<标题>RSS 标题</频道>
我该怎么做?
原以为 google-code-prettify 会完成这项工作,但看起来它不会缩进.使用额外的缩进插件 (vkbeautify) 可以获得带有缩进的正确 xml 格式.
http://plnkr.co/edit/Pep9HurLI8NPtAXRsoFD?p=preview
<pre class="prettyprint lang-xml"></pre>App.directive('prettyprint', function() {返回 {限制:'C',链接:函数 postLink(范围,元素,属性){element.text(vkbeautify.xml(scope.dom, 4));}};});
I have some data in string -
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel> </rss>" ;
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?
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=preview
<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));
}
};
});
这篇关于如何在angular js的html中显示xml文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!