Angularjs 如何注入d3依赖关系?

Angularjs 如何注入d3依赖关系?,angularjs,d3.js,Angularjs,D3.js,我是angularjs新手,我在main.js中注入d3如下: function (angular) { 'use strict'; angular.module('main', ['ngFileUpload', 'ngCookies', 'ui.router', 'd3']) .constant('_', window._); })(window.angular); 但我有一个错误: Unca

我是angularjs新手,我在main.js中注入d3如下:

      function (angular) {
            'use strict';

        angular.module('main', ['ngFileUpload', 'ngCookies', 'ui.router', 'd3'])
         .constant('_', window._);

      })(window.angular);
但我有一个错误:

       Uncaught Error: [$injector:modulerr] 
       Failed to instantiate module main due to:
           Error: [$injector:modulerr] Failed to instantiate module d3 due to:
         Error: [$injector:nomod] Module 'd3' is not available! You either              misspelled the module name or forgot to load it. If registering a module ensure              that you specify the dependencies as the second argument.

如果您使用的是普通d3库,则不会注入角度依赖项

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>

您可以使用d3.js角度指令或d3“wrappers”角度指令,我建议您:


d3是您的角度指令吗?或者只是lib js文件?只需将lib添加到索引中d3不是angular指令或模块,您不能以这种方式添加,但如果添加了js,您可以在控制器中使用d3,而不需要在angular.module中插入“d3”。您只需在index.html中导入d3.min.js脚本,就可以在任何地方调用d3.js函数。@IvanCoronado,我一直在注入它,该服务还将上面的脚本添加到DOM中,并在加载脚本时返回原始d3对象的承诺。如果你依赖于全局D3对象,它可能还没有被拉下来,这难道不能保证D3已经准备好使用了吗?