angular - 在 Visual Studio IDE 中创建/生成新的 Angular 组件的简单方法?

标签 angular visual-studio angular-components asp.net-core-mvc-2.0

从事 ASP.NET core 项目 (Angular) 和 Visual Studio 作为我的 IDE。

有没有一种简单的方法可以生成 Angular 组件文件并在 Visual Studio 的应用程序模块中注册新组件?

最佳答案

只需在 VS Code 中打开集成终端并使用 Angular CLI 命令 nggenerate 或其别名 ng g 即可。以下是可以与 ng g 命令一起使用的一些选项的列表:

  • ng g c - 生成新组件
  • ng g s - 生成新服务
  • ng g d - 生成新指令
  • ng g m - 生成新模块
  • ng g p - 生成一个新管道

每个命令都需要一个参数,例如要生成的组件的名称。要获取可用选项和参数的完整列表,请运行命令 ng help generated 或参阅 Angular CLI 文档。以下是使用 ng g 命令的一些示例:

  • ng g c Product 将为目录 src/app/product 中的新产品组件生成四个文件(.ts、.html、.css、.spec.ts),并将将 ProductComponent 类添加到 @NgModule 的声明属性中

  • ng g c Product -is -it -spec=false 将在 src/app/product 目录中生成具有内联样式和模板的单个文件product.component.ts,并将将 ProductComponent 添加到 @NgModule

  • 的声明属性
  • ng g s Product 将生成文件product.service.ts,其中包含用@Injectable() 修饰的类和文件product.service.spec.ts在目录 src/app

  • ng g s Product -m app.module 将生成与上述命令相同的文件,并将 ProductService 添加到 providers 属性中@NgModule

关于angular - 在 Visual Studio IDE 中创建/生成新的 Angular 组件的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46023050/

相关文章:

Angular 7响应式下拉菜单

angular - Angular 6 中的 Instascan 库面临问题

Angular2 Material Grid 全高

c - 我正在使用 Matlab 编码器开发 DLL。我需要为创建的 DLL 填写属性和详细信息,如版权、文件版本、产品名称等

html - Angular 2 : How to show inner HTML of component-tags inside of component?

angular - 无法绑定(bind)到 'Property X',因为它不是 'Child Component' 的已知属性

angular 2 ionic 2处理按键事件

c# - 如何解决 Blazor 服务器端项目的 Visual Studio 中的错误消息?

c# - Visual Studio 安装项目是否在卸载时保留了注册表项?

css - 如何将奇偶行 css 应用于动态加载的组件?