【发布时间】:2014-12-21 04:07:35
【问题描述】:
我正在尝试使用 MeanJS 框架让 d3 和 angular 一起工作。我已经使用了很多 D3,但对于 meanJS 和 angular 来说非常新。最佳实践似乎是将 d3 代码放在指令中。我已经创建了一个名为 customers 的 CRUD 模块,所以我使用了以下命令:
yo meanjs:angular-directive mus-example
这已经生成了指令文件,将其全部连接起来并给了我以下代码(我添加的评论除外):
'use strict';
angular.module('customers').directive('musExample', [
function() {
return {
template: '<div></div>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
//I want to add my d3 code here
element.text('this the musExample directive');
}
};
}
]);
我已经使用它进行了测试,一切都很好。该指令打印出 element.text 所以没问题
所以现在我想把我的 D3 代码放进去。我已经通过运行安装了 d3 凉亭安装 d3
这似乎更新了 env/all.js 文件,我可以在浏览器中看到 d3 加载。但是,一旦我尝试在指令中使用 D3 代码,就会出现如下错误。
public/modules/customers/directives/mus-example.client.directive.js
13 | var color = d3.scale.category10();
^ 'd3' is not defined.
我真正想要的是一些关于如何通过指令将 d3 挂钩到 meanJS 的 hello-world 示例。我认为有某种配置文件或者我没有用 d3 更新的东西,我很确定这真的很简单,但我仍然对 meanjs 不满意。连接 d3 和 Angular 真的很容易,这里发生的事情与我没有正确理解 meanjs 有关。
任何帮助将不胜感激。
【问题讨论】:
-
我应该补充一下——我确实更新了 MeanJS 应用程序中的 bower.json 文件和 all.js 文件。我还读到应该更新 applicationModuleVendorDependencies,但是当我在其中包含 d3 时,它会破坏一切
-
这里发生的另一件非常奇怪的事情是我在 console.log(d3) 中添加了上面的 d3 代码,我可以在控制台中看到它 - 所以它以某种方式已加载并可用。但我仍然收到上面的错误消息。
标签: javascript angularjs d3.js meanjs