问题
我正在尝试将 HTML 的 yfile 集成到使用 Angular CLI 的 Angular 2 应用程序中。我正在使用最新版本的 Angular 2 和 CLI 的最新 BETA 版本。
我已经使用npm install --save @types/yfiles
.
我已经在我的项目中放置了所需的 yfiles 文件夹,并更新了 angular-cli.json 以包含所需的样式和脚本:
"styles": [
"../lib/yfiles.css"
],
"scripts": [
"../lib/license.js",
"../lib/yfiles/view-component.js",
"../lib/yfiles/view-layout-bridge.js",
"../lib/yfiles/layout-hierarchic.js",
"../lib/yfiles/layout-tree.js",
"../lib/yfiles/router-polyline.js",
"../lib/yfiles/router-other.js"
],
我已经确认构建在运行后将这些脚本包含在捆绑的脚本输出中ng build
。
当尝试引用 yfiles 时,自动完成在 IDE(最新的 Webstorm)中工作:
graphComponent: yfiles.view.GraphComponent;
constructor(private element: ElementRef,
injector: Injector,
resolver: ComponentFactoryResolver) { }
ngAfterViewInit() {
let containerDiv:HTMLDivElement =
this.element.nativeElement.getElementsByClassName('graph-control-container')
[0];
this.graphComponent = new yfiles.view.GraphComponent(containerDiv);
}
该项目在发出时编译并运行,ng serve
但是当我导航到激活尝试使用 yfiles 的组件的路由时,会在控制台中引发错误并报告:
error_handler.js:54 EXCEPTION: Uncaught (in promise): Error: Error in ./BrowseVisualisationsComponent class BrowseVisualisationsComponent - inline template:0:0 caused by: Cannot read property 'GraphComponent' of undefined
我尝试过导入 yfiles 模块 - 例如:
import 'yfile/view-component'
这只是阻止ng serve
构建应用程序:
ERROR in ./src/app/shared/table-relationship-visualisation/table-relationship-visualisation.component.ts
Module not found: Error: Can't resolve 'yfiles/view-component' in '/home/VMdev/Documents/iotahoe_client/src/app/shared/table-relationship-visualisation'
@ ./src/app/shared/table-relationship-visualisation/table-relationship-visualisation.component.ts 12:0-31
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi main
任何帮助表示赞赏。