【发布时间】:2016-05-21 02:07:45
【问题描述】:
我正在尝试将 D3 包含到我的 Angular 应用程序中,但似乎无法从 Bower 安装中加载 D3,因为 Angular 说它找不到它或拼写错误。该应用程序设置为使用 gulp 获取 bower_components 并从那里构建。 d3 有什么不同之处使其无法包含在 gulp 构建过程中吗?
这是我的组件,我无法访问 D3 源代码。我不应该能够从凉亭安装中访问它吗?我见过一些堆栈溢出问题,他们说要创建一个简单的“d3”模块并在工厂中从中返回一个 d3 变量,但我从 window.d3 得到 undefined ...?
angular.module("diagram", ["d3"]).directive("ersDiagram", ["$compile", "$document", function($compile:ng.ICompileProvider, $document:ng.IDocumentService) {
return {
restrict: "E",
replace: true,
templateUrl: "diagram/template/diagram.html",
scope: {
nodes: "=",
edges: "=",
autoResizeGraph: "@?",
enableMouseWheelZoom: "@?",
selectedNode: "=?",
selectedEdge: "=?",
height: "@?",
onSelected: "&?",
onEdgeSelected: "&?",
direction: "@?",
enableZoomButtons: "@?"
},
controller: DiagramComponent,
bindToController: true,
controllerAs: "ctrl",
link: function (scope:ng.IScope, elem:ng.IAugmentedJQuery, attrs:ng.IAttributes, ctrl:any) {
//d3 code here
//get undefined for all d3 code
}
我不明白为什么我不能通过将 D3 注入应用程序来访问它?是否与 gulp 不将其包含在构建中有关?如果是常见情况,有人知道如何让 D3 包含在构建中吗?
卡了一段时间,非常感谢帮助!
如果您需要查看任何更具体的代码,请告诉我。
【问题讨论】:
标签: javascript jquery angularjs d3.js bower