Angular 8:禁止使用导入的零部件



使用的一个角度组件是从库中导入的。然而,该库还包含与第一组件相似的第二组件。使用它会导致一些不一致。所以我正在努力消除使用它。

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

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

我尝试在根组件上编写一个jasmine测试,以确保该组件永远不会被使用。但是,它可能会失败,因为第二个组件可以在ngIf中有条件地呈现。如果我可以以某种方式破坏第二个组件,从而在编译时构建失败,这也是可以的。感谢的任何帮助

您可以覆盖组件。

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

请查看此链接。

最新更新