gpt4 book ai didi

Angular:为什么 NO_ERRORS_SCHEMA 不适用于属性?

转载 作者:行者123 更新时间:2023-12-04 15:42:22 24 4
gpt4 key购买 nike

我正在编写我的第一个 Angular 测试,但在这里遇到了问题。我正在测试一个组件,其中有一个自定义属性

<ng-container *isGranted="admin">
...
</ng-container>

Official documentation

The NO_ERRORS_SCHEMA tells the Angular compiler to ignore unrecognized elements and attributes.

所以我将以下内容添加到我的 TestBed 配置中:

schemas: [NO_ERRORS_SCHEMA]

但是,我仍然收到一个错误:

Property binding isGranted not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations

我哪里错了?我不想测试 isGranted 的行为方式,我只想检查是否为其分配了正确的值。

最佳答案

您正在使用指令,而 NO_ERROR_SCHEMA 是忽略自定义组件。参见 github当抛出错误并提示您需要包含指令的异常时

Property binding ${prop.name} not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations".

关于Angular:为什么 NO_ERRORS_SCHEMA 不适用于属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57370096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com