[英]How do i prettify XML which is returned as a String in AngularJS
我有如下的HTML從Angular返回一些內容(我的角度代碼在下面)
<section>
<p>{{xml}}</p>
</section>
在Java后端的Angular中,我將這個“ XML”作為字符串獲取。
但是我想使用以下插件來美化它
https://github.com/krtnio/angular-pretty-xml
將插件包含在HTML文件中后,我不知道如何使用它,這是我尋求您幫助的地方。
app.controller('xmlController', function($scope, $http){
$http.get("/api/xml").then(function (response) {
$scope.xml = response.data; //I need to PRETTIFY IT HERE ON $scope.xml
});
});
好吧,我認為您在安裝過程中缺少了一些東西。
首先,您必須在應用程序上安裝軟件包:
通過涼亭:
bower install angular-pretty-xml --save
通過npm:
npm install angular-pretty-xml --save
確保將其包含在script
標簽內的html文件中(除非您使用的是諸如webpack之類的自動打包系統或將其打包的其他東西),以便您可以將其添加為對angular模塊聲明的依賴性 :
angular
.module('myApp', ['prettyXml'])
.controller('xmlController', function($scope, $http){
$http.get("/api/xml").then(function (response) {
$scope.xml = response.data; //I need to PRETTIFY IT HERE ON $scope.xml
});
});
這樣,您將可以在模板上使用過濾器,如下所示:
<p>{{ xml | prettyXml}}</p>
參考文獻:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.