gpt4 book ai didi

angular - 在创建 NG_VALUE_ACCESSOR 时 forwardRef 是强制性的

转载 作者:行者123 更新时间:2023-12-03 14:38:02 25 4
gpt4 key购买 nike

我有一个自定义输入组件,它使用声明如下的提供程序实现 ControlValueAccessor。它似乎工作正常。在我可以在互联网上找到的所有教程中,只要提供 NG_VALUE_ACCESSOR,就会广泛使用 forwardRef

将以下代码发送到生产环境是否安全?

providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: CustomInputComponent, //Notice I omitted forwardRef here and it works fine
multi: true
}]

最佳答案

forwardRef使 Angular 能够在定义之前注入(inject)依赖项。在这种情况下,如果此提供程序数组定义在 @Component你提到的自定义输入组件的装饰器,它会起作用,因为在定义类后应用了装饰器 .

基本上,您可以删除 forwardRef只要您仅使用它来引用同一组件的装饰器内的组件。

See here for in depth reading

关于angular - 在创建 NG_VALUE_ACCESSOR 时 forwardRef 是强制性的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62047908/

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