Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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-将JSON文本复制到新窗口中的textarea_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS-将JSON文本复制到新窗口中的textarea

Javascript AngularJS-将JSON文本复制到新窗口中的textarea,javascript,angularjs,Javascript,Angularjs,我有一个调用JSON响应的服务,我想将这个JSON响应复制到一个新窗口中的textarea。在AngularJS中有没有这样做的方法 到目前为止,我所拥有的: GetData.getJson(item).then(function(returnValues){ var data = returnValues[0].data; // a json object as a string, ideally I would like to pretty print this in the new

我有一个调用JSON响应的服务,我想将这个JSON响应复制到一个新窗口中的textarea。在AngularJS中有没有这样做的方法

到目前为止,我所拥有的:

GetData.getJson(item).then(function(returnValues){
    var data = returnValues[0].data; // a json object as a string, ideally I would like to pretty print this in the new window.

    // need to create text area in the new window so I can paste the text in
    $window.open("data:text/html,"+ encodeURIComponent(data), "_blank", "width=800,height=600");

}

我发现Angular可以很容易地做到这一点,我只是不太熟悉打开新窗口

GetData.getJson(productNumber).then(function(returnValues){
    var data = JSON.stringify(returnValues[0].data, null, 4); // pretty print
    data = "<textarea cols='100' rows='150'>" + data + "</textarea>"; // encase in text area
    $window.open("data:text/html,"+ encodeURIComponent(data), "_blank", "width=800,height=600");
});
GetData.getJson(productNumber).then(函数(returnValues){
var data=JSON.stringify(返回值[0].data,null,4);//漂亮的打印
data=“”+data+”;//封装在文本区域中
$window.open(“数据:text/html,”+encodeURIComponent(数据),“_blank”,“宽度=800,高度=600”);
});