Javascript AngularJS-将JSON文本复制到新窗口中的textarea
我有一个调用JSON响应的服务,我想将这个JSON响应复制到一个新窗口中的textarea。在AngularJS中有没有这样做的方法 到目前为止,我所拥有的: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
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”);
});