是否有一种方法可以访问实现ControlValueAccessor的组件中的主机?

发布于 2025-01-31 10:01:42 字数 556 浏览 3 评论 0原文

通过主机,我了解使用了我的组件的范围。如果将其定义为< my-component>,则在某个地方使用的地方:

< my-component name =“ test” class =“ test-class”#test =“ test-class”#test =“ ngmodel” [(ngmodel)] =“ data.test”必需>

,然后我想:

  • 知道是否将主机组件应用于其上。
  • 获取所有应用于NGMODEL的验证器(IE RueldsValidator)
  • 知道NGModel属于的表格是否已出于

某种原因提交(不引入自己的自定义属性),我无法可靠地获得。我知道:

  • 主机点,但这仅是一种方式,并且可以在主机上应用类,但没有对已经有哪些类已经有
  • 元素注入的类别进行更新,我可以在这里进行本地元素和道具。这给了我课程(但水平非常低),但没有验证器 / ngmodel。

这里不允许在主机元素上访问NGMODEL“上面”?

By host, I understand the scope of where my component is used. If it is defined as <my-component>, then if it’s used somewhere as:

<my-component name=“Test” class=“test-class” #test=“ngModel” [(ngModel)]=“data.test” required>

then I would like to:

  • know if host component has a certain css class (i.e. test-class) applied to it.
  • get all the validators that are applied to the ngModel there (i.e. RequiredValidator)
  • know if form that ngModel belongs to has been submitted (without introducing own custom property)

For some reason, I couldn’t get to it reliably. I know of:

  • HostBinding, but that is sadly one way only and can apply classes on host, but is not updated with regards to what classes already are there
  • ElementRef injection, where I can get to nativeElement and props. That gives me classes (but very low level), but not validators / ngModel.

Is the access to ngModel “above” on the host element not allowed here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文