首页 > 解决方案 > Angular 8:禁用导入的组件

问题描述

正在使用的角度组件之一是从库中导入的。但是,该库还包含与第一个组件类似的第二个组件。使用它会导致一些不一致。所以我试图消除使用它。

目前,无法更改库,因为第一个组件在多个地方使用。有没有办法禁用第二个组件?

<first-component></first-component> <!--Should work-->

<second-component></second-component> <!--Should not work-->

我尝试在根组件上编写一个 jasmine 测试,以确保该组件永远不会被使用。但是,它可能会失败,因为第二个组件可以有条件地在 ngIf 中呈现。如果我能以某种方式毒化第二个组件,以便在我编译时构建失败,那也没关系。任何帮助表示赞赏

标签: angularjasmine

解决方案


您可以覆盖该组件。

fixture = TestBed.overrideComponent(SecondComponent, { set: { template: '<span>Hello</span> }}).createComponent(SecondComponent);

检查链接。


推荐阅读