且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在自定义元素上实现 ngModel?

更新时间:2023-10-14 08:44:52

我认为这个链接可以回答你的问题:

I think this link will answer your question:

我们需要实现两件事来实现这一目标:

We need to implement two things to achieve that:

  • 提供表单组件逻辑的组件.它不需要输入,因为它将由 ngModel 本身提供
  • 一个自定义的 ControlValueAccessor 将实现这个组件和 ngModel/ngControl
  • 之间的桥梁
  • A component that provides the logic of your form component. It doesn't need an input since that will be provided by ngModel itself
  • A custom ControlValueAccessor that will implement the bridge between this component and ngModel / ngControl

上一个链接为您提供了一个完整的示例...

The previous link gives you a complete sample...