我想使用反应式将2个值连接成1个标签。在这种情况下,我不使用ngModel绑定。
<label
id="identificationCode"
name="identificationCode"
formControlName="lblIdCode">______</label>
<input type="text"
id="reference"
name="reference"
formControlName="txtReference"
maxlength="250"
(change)="handleIdCode($event)">
<input type="text"
id="publicacion"
name="publicacion"
formControlName="txtPublicacion"
maxlength="250"
(change)="handleIdCode($event)">
我想在用户书写时连接这2个输入文本,并自动将值反映到标签中。有没有什么办法像我们那样在没有更改事件的情况下进行模型绑定?
一种方法是可以使用引用变量来引用模板中的控件。像这样
<label
id="identificationCode"
name="identificationCode">{{reference.value + " - " + publicacion.value}}</label>
<input type="text"
id="reference"
name="reference"
formControlName="txtReference"
maxlength="250"
#reference>
<input type="text"
id="publicacion"
name="publicacion"
formControlName="txtPublicacion"
maxlength="250"
#publicacion>
的重要的部分是#reference
和#publicacion
每个的输入端。这会将控件链接到变量。
然后,您可以在像这样的Angular插值块中使用这些变量{{reference.value + " - " + publicacion.value}}
。您可以在此块中组合所需的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句