简体   繁体   English

如何在angular2应用中循环/计数组件?

[英]How to loop/count components in an angular2 app?

Basically the title says all. 标题基本上说明了一切。 How would I loop through all of my components or just get the number of them in my project. 我将如何遍历我的所有组件,或者仅获得我项目中的组件数量。 Let's say I have 15 components in my angular2 application. 假设我的angular2应用程序中有15个组件。 How to display this number? 如何显示这个数字? Without including them in the main app.components.html ? 没有在主app.components.html中包含它们?

You can write a script that goes through your project and looks for components. 您可以编写一个贯穿项目并查找组件的脚本。

for windows: open a command prompt, navigate to yourproject/src , the following commant will return the amount of components: 对于Windows:打开命令提示符,导航到yourproject/src ,以下命令将返回组件数量:

dir /s | find /c "component.ts"

You can add >file.txt to the end to save this number a file. 您可以在末尾添加>file.txt ,以将该编号保存为文件。

Now you can read from this file from your application and display the number. 现在,您可以从应用程序中读取此文件并显示编号。

- -

You can also leave out the /c for a list of all the components 您也可以省略/c以获得所有组件的列表

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

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