简体   繁体   English

如何在 angular 6 项目中使用 javascript npm?

[英]How can I use javascript npm in angular 6 project?

I am new to Angular 6 and I do not know how to use npm i d3-dtree in Angular 6. How can I use Javascript libraries using npm , especially for Angular 6? I am new to Angular 6 and I do not know how to use npm i d3-dtree in Angular 6. How can I use Javascript libraries using npm , especially for Angular 6?

I want to create family-tree like this fiddle using d3-dtree .我想使用d3-dtree创建像这个小提琴这样的家谱。 Can anyone give me guide or demo how to use d3-dtree with npm in StackBlitz's link?谁能给我指导或演示如何在 StackBlitz 的链接中将d3-dtreenpm一起使用?

I think you can now understand npm as library installer.我想您现在可以npm理解为库安装程序。 It definitely does more than that, eg, it can serve web pages, but think it in that way for now...它肯定不止于此,例如,它可以提供 web 页面,但现在以这种方式考虑......

I had used plain Javascript for a long time in .html files.我在.html文件中使用了普通的 Javascript 很长时间。 So it was very difficult for me to get used to how modern Javascript family works these days.所以我很难适应现代 Javascript 家族这些天的工作方式。 For example, you do not need HTTP server to place .html files and serve web pages.例如,您不需要 HTTP 服务器来放置.html文件并提供 web 页面。

So start your Angular project in a server device using Angular CLI which is supported by npm .因此,使用 npm 支持的npm CLI在服务器设备中启动您的 Angular 项目。 Then in your project folder, do npm i d3-dtree and install the library.然后在您的项目文件夹中,执行npm i d3-dtree并安装库。 You can import and use the library in a different way as you did inside .html files in old fashion.您可以像在老式的.html文件中那样以不同的方式导入和使用该库。

For angular, Go inside the project and run npm install d3 angular-d3-tree Then add the module in import array in app.module.ts .对于 angular, Go 在项目内部运行npm install d3 angular-d3-tree然后在app.module.tsimport数组中添加模块。

Demo: https://stackblitz.com/edit/angular-d3-tree演示: https://stackblitz.com/edit/angular-d3-tree

For more details go to https://github.com/jgpATs2w/angular-d3-tree有关更多详细信息 go 到https://github.com/jgpATs2w/angular-d3-tree

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM