我无法在 asp.net core spas 中添加带有 angular cli 的新组件 [英] I can't add new component with angular cli in asp.net core spas

查看:26
本文介绍了我无法在 asp.net core spas 中添加带有 angular cli 的新组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 asp.net core 2.0 SPA 中添加一个新组件,其中 angular 4 带有 angular cli 和此版本:><块引用>

@angular/cli: 1.4.2

节点:8.4.0

操作系统:Linux x64

当我在组件目录上运行此命令 ng g c vehicle-form 时出现此错误:

<块引用>

错误:找不到新组件的 NgModule.使用 skip-import 选项跳过在 NgModule 中导入组件.找不到新组件的 NgModule.在 NgModule 中使用跳过导入选项跳过导入组件.

app.module.shared.ts

另外,我有 3 个 app.module.ts 文件,而不是一个 :\ :

app.module.browser.ts

app.module.shared.ts

app.module.server.ts

解决方案

您在一个未考虑使用 CLI 构建的项目中使用 Angular CLI,因此您必须采取一些额外的步骤.错误消息告诉您要执行的操作.

首先,运行 ng g c vehicle-form 命令并包含 --skip-import=true 选项.

然后,手动在适当的应用程序模块文件中添加组件声明.在本例中,是 app.module.shared.ts,其中声明了所有其他应用程序组件.

或者,您可以运行 ng g c Vehicle-form 并包含 --module='app.module.shared.ts'.您可能必须使用此完全限定模块文件的路径.我还没有测试过,所以准备好自己尝试一些事情.

有关 ng 生成组件的更多信息:生成组件.

更新 (2018-03-01)

Microsoft 提供了一些用于 ASP.NET Core 2.0 应用程序的新 SPA 模板.您可以在此处找到有关它们的更多详细信息.新的 Angular 模板 包括对 Angular CLI.因此,如果您熟悉 CLI,那么这应该会让人感觉更像家.这意味着您可以使用 ng g 命令来使用这个新模板生成代码.

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

node: 8.4.0

os: Linux x64

when I running this command ng g c vehicle-form on a directory of components got this error:

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

Also, I have 3 files for app.module.ts not one :\ :

app.module.browser.ts

app.module.shared.ts

app.module.server.ts

解决方案

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.

First, run the ng g c vehicle-form command and include the --skip-import=true option.

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.

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.

More on ng generate component: generate component.

UPDATE (2018-03-01)

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 core spas 中添加带有 angular cli 的新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆