【发布时间】:2020-09-15 20:55:24
【问题描述】:
想弄清楚这一点,我头疼不已。我想创建一个可以在 Angular/Ionic 应用程序中使用的自定义输入元素。如何将 Angular 属性与这些自定义元素一起使用,例如 FormControlName。
<my-custom-stencil-input type="text" formControlName="firstName"></my-custom-stencil-input>
我有以下代码,但是当我尝试使用 FormControlName 时它显示错误。
import { Component, h, Prop } from '@stencil/core';
@Component({
tag: 'ba-text-input-one',
styleUrl: './text-input-1.component.css',
scoped: true,
})
export class TextInputOne {
@Prop({reflect: true}) type: string;
@Prop({reflect: true}) placeholder: string;
@Prop({reflect: true}) formControlName: string;
render() {
return (
<div id="cmp">
<div id="icon-area">
<slot name="icon"></slot>
</div>
<input id="input-field" formControlName={this.formControlName} type={this.type} />
</div>
);
}
}
Stencil 上的文档对于如何处理这个问题不是很详尽。
基本上,我想以 Angular 反应形式使用我自己的自定义 Stencil 输入元素。
【问题讨论】:
-
在您的示例中,您实际上是将
formControlName添加到input元素,而不是my-custom-stencil-input。另外,您是否生成了Angular bindings? -
如何生成 Angular 绑定? ValueAccessorConfigs 没有很好地解释。
标签: angular ionic-framework angular-reactive-forms stenciljs