我正在尝试创建一个自定义输入文本组件,但我不知道如何使其与ngModel
指令一起使用。
我已经尝试复制material angular_component input,但不了解inputText
属性实际上是如何链接到ngModel
值的,以及DefaultValueAccessor
指令的用途是什么。
这是我期望使用组件的方式:
<my-input-component [(ngModel)]="someProp"><my-input-component>
((my-input-component
的内容只是带有标签的普通<input type="text">
字段)
任何想法或示例/文档的链接将不胜感激。
您可以使用@Input
将数据模型从父代传递到子代。在子级中,它将ngModel
绑定到从父级传递到子级的ngModel
。参见Angular Component Interaction。但是您不应该使用ngModel
作为Input的名称,因为ngModel
是输入标签的默认属性,并且可能造成混淆。