我有一个调用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");
}
答案 0 :(得分:2)
我发现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");
});