2014-02-27 1 views
1

JSON 응답을 요구하는 서비스가 있습니다.이 JSON 응답을 새 창에서 텍스트 영역에 복사하고 싶습니다. 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"); 
});