Angular Js 中的模块和库有什么区别

What is difference between module and library in Angular Js

我正在研究 nvd3 and c3js where both depends on d3js. Here for nvd3 we need to inject "nvd3" as dependency injection where as for c3js 我们只提供文件路径,我们不会注入任何东西。

任何人都可以解释实施 nvd3 and c3js 的区别。

谢谢。

似乎你需要两者 给出文件路径 注入一个依赖。我认为您将 angular-nvd3 称为 nvd3

angular-nvd3 是一个 angular 模块,它包装了原始的 nvd3 图表库。它具有 angular 指令 以帮助您在 angular 应用程序中使用 nvd3 图表(具有绑定等)。

例如(view it online):

<nvd3 options="options" data="data" class="with-3d-shadow with-transitions"></nvd3>

你必须在 angular 中使用 "dependecy injection" 的原因是因为 angular 与第三方模块集成:当您想使用第三方 angular 模块 时,您需要在应用程序模块定义中将其声明为依赖项。

例如,此语法意味着您声明一个名为 myApp 的 angular 应用程序并且它依赖于 angular-nvd3 :

angular.module('myApp', ['nvd3'])
    .controller(...)
    .service(...)

除此之外,您需要在主 html 文件中包含第 3 方库代码,例如:

<meta charset="utf-8">  <!-- it's important for d3.js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/d3/d3.js"></script>
<script src="bower_components/nvd3/nv.d3.js"></script> <!-- or use another assembly -->
<script src="bower_components/angular-nvd3/dist/angular-nvd3.js"></script>
<link rel="stylesheet" href="bower_components/nvd3/nv.d3.css">