1

我想在使用 Puppeteer 的 Node.js 中创建代码,然后将此操作添加到ng-clickAngular 中。

所以我在 Node.js 中有 Puppeteer 代码:

const puppeteer = require('puppeteer');

    (async () => {
      const browser = await puppeteer.launch();
      const page = await browser.newPage();
      await page.goto('/vWniosekurl_form.html', {waitUntil: 'networkidle'});
      await page.pdf({path: 'images/asd.pdf', format: 'A4'});

      browser.close();
    })();

如何将其与ng-clickAngular 动作联系起来?

我想在我的 Angular 控制器中试试这个:

$scope.pupp = function(){
 router.get('/pdf', function(req, res){
  var request = $http.get('/data');    
  request.success(function(data) {
    $scope.data = data;
 });
 request.error(function(data){
    console.log('Error: ' + data);
})};

在我的 Node.js 文件 app.js 中:

router.get('/pdf', function(req, res){
    const puppeteer = require('puppeteer');

    (async () => {
      const browser = await puppeteer.launch();
      const page = await browser.newPage();
      await page.goto('/vWniosekurl_form.html', {waitUntil: 'networkidle'});
      await page.pdf({path: 'images/asd.pdf', format: 'A4'});

      browser.close();
    })();
});
4

1 回答 1

0

获取对匿名函数返回的引用Promise,然后添加解决方法:

let myPromise = (async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('/vWniosekurl_form.html', {waitUntil: 'networkidle'});
  await page.pdf({path: 'images/asd.pdf', format: 'A4'});

  browser.close();
})();
myPromise.then(function(){ // do stuff })
于 2017-09-19T00:43:23.480 回答