2016-03-23 47 views
0

我有一個角度應用程序,使用angular-ui-router。
頁我已經建成看起來很好。 我想拍一張html的快照並創建一個pdf。
爲此,我使用Phantom。帶節點和角度的幻影Js-ng-repeat不呈現

我可以觸發並創建PDF罰款,但它不呈現我的HTML重複部分。

我的HTML:

<div>{{vm.hello}}</div> 
<div class="row"> 
    <div class="col-xs-2">Heading</div> 
</div> 
<div class="row" ng-repeat="record in vm.records"> 
    <div class="col-xs-2">Space</div> 
    <div class="col-xs-2" ng-bind="record.id"></div> 
</div> 

我控制器上的負載觸發來填充vm.records。 vm.hello被硬編碼並呈現正常。
我的ng重複加載沒有任何東西。

我的節點js代碼:

var phantom = require('phantom'); 
function pdf(req, res) { 
    console.log('pdf function entered'); 
    var url = "http://myapp.com/page"; 
    phantom.create().then(function(ph) { 
    ph.createPage().then(function(page) { 
     page.viewportSize = { 
     width: 1400, 
     height: 1024 
     }; 

     page.property('onLoadFinished', function(status) { 
     console.log("Load Finished with status " + status); 
     }); 

     page.open(url).then(function(status) { 
      page.render('test.pdf', { 
      format: 'pdf', 
      quality: '100' 
      }).then(function() { 
      console.log("File Created"); 
      page.close(); 
      ph.exit(); 
      }); 
     }); 
    }); 
    }); 
    res.status(200).send(); 
} 

任何人都可以提供一些線索,爲什麼NG重複將無法正常工作?我試過在其他問題/答案中添加延遲,但似乎無法使其工作。

+0

您使用哪個PhantomJS版本?請註冊'onConsoleMessage','onError','onResourceError','onResourceTimeout'事件(舊的[示例](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-3_phantomnodeerrors-js),所以它可能不以完全相同的方式工作)。也許有錯誤。 –

回答

0

在你的控制器,你必須調用

window.callPhantom(); 

完成

當渲染

下一個是你要叫它$超時裏面這樣

$timeout(function(){ 
      window.callPhantom(); 
      return; 
}) 

避免叫它綁定之前