2014-02-27 136 views
1

我有一个服务调用了JSON响应,我想将此JSON响应复制到新窗口中的textarea。有没有办法在AngularJS中做到这一点?AngularJS - 在新窗口中将JSON文本复制到textarea

我有什么至今:

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"); 

} 

回答

2

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

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"); 
});