我正在尝试使用angular cli 1.7.4 + angular 5.2.10 + unitegallery 1.7.28所以我在main.ts中使用:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import './provider-plugin';
import 'bootstrap';
import 'unitegallery/dist/js/unitegallery.js';
import 'unitegallery/dist/themes/tiles/ug-theme-tiles.js';
//
import { AppModule } from './app/app.module';
...
provider-plugin.ts(没有 unitegallery.js 报告 jQuery 缺失)是:
/*!
ProvidePlugin
*/
import * as $ from 'jquery';
window['$'] = $;
window['jQuery'] = $;
window['jquery'] = $;
在浏览器中,我看到 vendor.bundle.js 正确订购 unitegallery.js 和 ug-theme-tiles.js 但是当页面加载时我会收到这些错误:
jQuery.Deferred exception: g_ugFunctions is not defined ReferenceError: g_ugFunctions is not defined
at HTMLDocument.eval (webpack-internal:///./node_modules/unitegallery/dist/themes/tiles/ug-theme-tiles.js:5:36)
at mightThrow (webpack-internal:///./node_modules/jquery/dist/jquery.js:3534:29)
at process (webpack-internal:///./node_modules/jquery/dist/jquery.js:3602:12)
at ZoneDelegate.invokeTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:421:31)
at Zone.runTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:188:47)
at ZoneTask.invokeTask (webpack-internal:///./node_modules/zone.js/dist/zone.js:496:34)
at ZoneTask.invoke (webpack-internal:///./node_modules/zone.js/dist/zone.js:485:48)
at timer (webpack-internal:///./node_modules/zone.js/dist/zone.js:2054:29) undefined
jQuery.Deferred.exceptionHook @ jquery.js:3818
process @ jquery.js:3606
ZoneDelegate.invokeTask @ zone.js:421
Zone.runTask @ zone.js:188
ZoneTask.invokeTask @ zone.js:496
ZoneTask.invoke @ zone.js:485
timer @ zone.js:2054
setTimeout (async)
scheduleTask @ zone.js:2075
ZoneDelegate.scheduleTask @ zone.js:407
Zone.scheduleTask @ zone.js:232
Zone.scheduleMacroTask @ zone.js:255
scheduleMacroTaskWithCurrentZone @ zone.js:1114
(anonymous) @ zone.js:2090
proto.(anonymous function) @ zone.js:1394
(anonymous) @ jquery.js:3640
fire @ jquery.js:3268
fireWith @ jquery.js:3398
fire @ jquery.js:3406
fire @ jquery.js:3268
fireWith @ jquery.js:3398
ready @ jquery.js:3878
completed @ jquery.js:3888
ZoneDelegate.invokeTask @ zone.js:421
Zone.runTask @ zone.js:188
ZoneTask.invokeTask @ zone.js:496
invokeTask @ zone.js:1540
globalZoneAwareCallback @ zone.js:1566
zone.js:192 Uncaught ReferenceError: g_ugFunctions is not defined
at HTMLDocument.eval (ug-theme-tiles.js:5)
at mightThrow (jquery.js:3534)
at process (jquery.js:3602)
at ZoneDelegate.invokeTask (zone.js:421)
at Zone.runTask (zone.js:188)
at ZoneTask.invokeTask (zone.js:496)
at ZoneTask.invoke (zone.js:485)
at timer (zone.js:2054)
unitegallery.js包含声明:
var g_ugFunctions = new UGFunctions();
那么问题是什么或如何解决这个问题?
修改
简单地连接这两个unitegallery js文件时工作正常:
// import 'unitegallery/dist/js/unitegallery.js';
// import 'unitegallery/dist/themes/tiles/ug-theme-tiles.js';
import 'unitegallery/dist/themes/tiles/unitegallery+ug-theme-tiles.js';