Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何美化在AngularJS中作为字符串返回的XML_Javascript_Java_Angularjs_Html - Fatal编程技术网

Javascript 如何美化在AngularJS中作为字符串返回的XML

Javascript 如何美化在AngularJS中作为字符串返回的XML,javascript,java,angularjs,html,Javascript,Java,Angularjs,Html,我的HTML如下所示,从Angular返回一些东西(我的Angular代码如下) 嗯,我认为您在安装过程中遗漏了一些东西 首先,您必须在应用程序上安装软件包: 维亚鲍尔: bower install angular-pretty-xml --save 通过npm: npm install angular-pretty-xml --save 确保将其包含在html文件中脚本标记中(除非您正在使用一些自动打包系统,如webpack或其他为您打包的东西),以便根据角度模块声明将其添加为依赖项,如下

我的HTML如下所示,从Angular返回一些东西(我的Angular代码如下)


嗯,我认为您在安装过程中遗漏了一些东西

首先,您必须在应用程序上安装软件包:

维亚鲍尔:

bower install angular-pretty-xml --save
通过npm:

npm install angular-pretty-xml --save
确保将其包含在html文件中
脚本
标记中(除非您正在使用一些自动打包系统,如webpack或其他为您打包的东西),以便根据角度模块声明将其添加为依赖项,如下所示:

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>
{{xml|prettyXml}

参考文献:


为什么需要这样做?可能是过滤器,它应该用作
{{xml | prettyXml}

,但这是在黑暗中拍摄的,因为目前我无法尝试。@w我尝试时会出错。我发现这里提到的解决方案非常有趣:
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>