angular - 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);
检查此链接。
推荐阅读
- python - 在 Pycharm Community 2019.3 中安装本地、下载的 WHL 文件
- asp.net-core - EditorFor Tag Helper 在使用 FluentValidator 时不呈现验证属性
- amazon-web-services - AWS Lambda 处理电子邮件附件数据?
- swift - 从 Interface Builder 加载具有通用约束的 UIView 子类的解决方法?
- ruby-on-rails - 为什么在测试期间构建的对象在测试期间消失(使用 RSPEC/Rails 5.2)?
- algorithm - 跟踪三次插值路径
- firebase - 如何根据flutter中的文档ID从单独列表中的集合中获取文档的每个值
- audio - 结合cdg和mp3时如何使ffmpeg尊重“start_time”变量?
- c# - 如何将数组复制到具有固定数组的结构?
- python - 从 CSV 文件的字段中删除嵌入的换行符