有两种使用第三方库(BrowserPrint.js)的环境;
WORKING ENV-JS和jQuery
在文档的<head>
部分中仅包含3party库
并且主函数在
中调用$(document).ready(setup_web_print);
NOT WORKING ENV-Angular,JS和jQuery
其中第三方库包含在组件中:
import * as $ from 'jquery';
import * as bp from '../../../content/js/BrowserPrint-1.0.4.js';
并在ngOnInit()
生命周期挂钩中触发:
ngOnInit() {
$(document).ready(function () {
...
})
...
}
控制台出现错误
ReferenceError: finishedFunction is not defined
at Object.t.getDefaultDevice (BrowserPrint-1.0.4.js:95)
因此它似乎无法访问finishedFunction
var a = n("GET", e("available"));
a && (finishedFunction = function(e) {
response = e, response = JSON.parse(response);
for (var n in response)
if (response.hasOwnProperty(n) && response[n].constructor === Array) {
arr = response[n];
for (var i = 0; i < arr.length; ++i) arr[i] = new t.Device(arr[i])
}
return void 0 == o ? void r(response) : void r(response[o])
}, i(void 0, a, finishedFunction, s), a.send())
有人知道如何解决此问题,为什么在第二个env中不起作用?
答案 0 :(得分:1)
我真的不知道JavaScript如何处理此逗号编写的代码。但是我想这就是您想要的,不是吗?
if(a) {
var finishedFunction = function(e) {
if (response = e, "" == response) return void s(null);
response = JSON.parse(response);
var n = new t.Device(response);
s(n)
};
i(void 0, a, finishedFunction, o);
a.send();
}