我正在致力于一个具有核心,共享和功能模块的Angular 应用程序.我有机会用新的独立组件一点一点地更新应用程序.但它并不是在所有地方都管用.

这是一个堆叠闪电战演示:https://stackblitz.com/edit/stackblitz-starters-2repu6?file=src%2Fmain.ts (对不起,我不知道如何在Stackblitz上启动它)

在某些情况下,我成功地使Work成为独立组件,但在共享组件或功能模块的子组件中除外. 我得到的错误是:[Error]NG8001:‘app-Standonly’不是已知元素

我不明白出了什么问题.即使在阅读了有关独立组件的内容后也是如此.也许这很简单.但我不明白我错过了什么.

太平绅士

推荐答案

1.独立组件:Works

没问题,因为你是懒惰加载StandaloneComponent (standalone: true),因为它有StandaloneChildComponent (standalone: true)在它的导入,它的加载没有任何问题!


2.功能组件:Works

没问题,在FeatureModule的Imports数组中有StandaloneComponent (standalone: true),这意味着我们可以在FeatureComponent的html中将其用作<app-standalone />


3.功能下级组件:不起作用!

问题是,因为没有将FeatureChildComponent (standalone: false)添加到FeatureModule的声明数组中,这就是为什么您会得到'app-standalone' is not a known element的错误.由于StandaloneComponent存在于FeatureModule的导入中,我们需要在FeatureModule中有FeatureChildComponent个声明才能使用app-standalone


特征中的共享组件:不起作用!

问题是,因为没有将SharedComponent (standalone: false)添加到SharedModule的声明数组中,这就是您收到'app-standalone' is not a known element的错误的原因.由于StandaloneComponent是在SharedModule的进口中,我们需要在SharedModule中有SharedComponent的声明才能使用app-standalone


Note: When you have a standalone component, that needs to be used in scenarios other than routing, add it to the imports array of a module/standalone component!

stackblitz

Angular相关问答推荐

为什么这个拦截器只在发送事件上触发,而不是在实际响应上触发?

存储服务存储在本地存储中,但无法检索到它

向Anguar 17项目添加服务以启动和停止Loader-NGX-UI-Loader

属性';apiUrl';在我的Angular 应用程序上不存在类型';{}';错误

如何在AngularJs中剪断细绳

Angular 16 Auth Guard在具有0的服务时给出Null Injector错误;httpclient;被注入

npm install命令在基本Angular 应用程序的天蓝色构建管道中失败

包含与 ngFor 相关内容的 HTML 输入

当访问令牌在 MSAL for Angular 中过期时如何重定向用户?

关闭 Dynamsoft Web Twain 弹出窗口

Angular [disabled]="MyBoolean" 没有工作

Angular2订阅对子组件中@Input的更改

由router-outlet 创建时如何将css类应用于组件元素?

Angular 2 通过 [class.className] 绑定添加多个类

无法从模块it was neither declared nor imported导出服务

Angular7 中的 CORS 策略已阻止源http://localhost:4200

如何在 Angular cli 项目中包含来自 node_modules 的assets

如何处理Angular2中的查询参数

Angular 5 和material - 如何从 SnackBar 组件更改背景 colored颜色

如何使用无头浏览器运行测试?