Wkhtmltopdf修补了angularjs的QT问题

时间:2016-07-05 10:30:44

标签: angularjs wkhtmltopdf

使用修补后的Qt运行任何版本的wkhtmltopdf时出现此JavaScript错误:

Warning: undefined:0 Error: [$injector:modulerr] Failed to instantiate module ng due to:
'undefined' is not an object
http://errors.angularjs.org/1.5.7/$injector/modulerrp0=ng&p1='undefined'%20is%20not%20an%20object

(我试图使用angularjs 1.5渲染页面。)

当我在没有修补Qt的情况下使用wkhtmltopdf版本时,我没有收到错误,一切正常。

我使用this heroku buildpack安装版本0.12.3并修补了Qt,我收到了此错误。

知道如何解决我的问题吗?我可以在没有修补Qt的情况下安装wkhtmltopdf,但似乎我必须编译它......

1 个答案:

答案 0 :(得分:7)

我终于设法使它适用于所有版本:我需要特殊版本的.bind()JavaScript函数polyfill:

var isFunction = function (o) {
return typeof o == 'function';
};

var bind,
slice = [].slice,
proto = Function.prototype,
featureMap;

featureMap = {
'function-bind': 'bind'
};

function has(feature) {
  var prop = featureMap[feature];
  return isFunction(proto[prop]);
}

// check for missing features
if (!has('function-bind')) {
  // adapted from Mozilla Developer Network example at
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
  bind = function bind(obj) {
    var args = slice.call(arguments, 1),
      self = this,
      nop = function() {
      },
      bound = function() {
        return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments)));
      };
    nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined
    bound.prototype = new nop();
    return bound;
  };
  proto.bind = bind;
}