I want to add a new component in asp.net core 2.0 SPAs with angular 4 with angular cli with this version: @ angular/cli:1.4.2 @angular/cli: 1.4.2节点:8.4.0操作系统:Linux x64os: Linux x64当我在组件目录上运行此命令ng g c vehicle-form时收到此错误:when I running this command ng g c vehicle-form on a directory of components got this error: 错误:找不到新组件的NgModule.使用skip-import选项可以跳过NgModule中的组件导入. 找不到新组件的NgModule.使用skip-import选项可以跳过NgModule中的组件导入. Error: Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule. Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule. app.module.shared.ts另外,我有3个app.module.ts的文件,而不是一个:\:Also, I have 3 files for app.module.ts not one :\ : app.module.browser.ts app.module.shared.ts app.module.server.ts推荐答案您在一个不考虑CLI的项目中使用了Angular CLI,因此您必须采取一些额外的步骤.错误消息告诉您您想做.You're using the Angular CLI in a project that wasn't built with the CLI in mind, so you have to take a couple of extra steps. The error message tells you want to do.首先,运行ng g c vehicle-form命令并包含--skip-import=true选项.First, run the ng g c vehicle-form command and include the --skip-import=true option.然后,手动将组件声明添加到适当的应用程序模块文件中.在这种情况下,app.module.shared.ts声明了所有其他应用程序组件.Then, add the component declaration in the proper application module file by hand. In this case, the app.module.shared.ts, where all the other application components are declared.或者,您可以运行ng g c vehicle-form并包含--module='app.module.shared.ts'.您可能需要使用此文件来完全限定模块文件的路径.我还没有测试过,所以准备自己尝试一些操作.Or, you can run the ng g c vehicle-form and include the --module='app.module.shared.ts'. You may have to fully qualify the path to the module file with this. I haven't tested it, so be prepared to try a few things with this on your own.有关ng生成组件的更多信息:生成组件.More on ng generate component: generate component. 更新(2018-03-01)UPDATE (2018-03-01) Microsoft提供了一些新的SPA模板,可与ASP.NET Core 2.0应用程序一起使用.您可以在此处找到有关它们的更多详细信息.新的角度模板包括对 Angular CLI .因此,如果您熟悉CLI,那么应该会觉得有点像家.这意味着您可以使用 ng g 命令来使用此新模板生成代码Microsoft has delivered some new SPA templates for use with ASP.NET Core 2.0 applications. You can find more details about them here. The new Angular template includes support for the Angular CLI. So, if you are familiar with the CLI, then this should feel a little bit more like home. This means you can to the ng g commands to generate code with this new template. 这篇关于我无法在asp.net核心spa中添加带有角度cli的新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 11:04