使用带有< span>之类的formControlName [英] use formControlName with something like <span>

查看:142
本文介绍了使用带有< span>之类的formControlName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态表格,其中显示了我通过REST获得的多个数据集. 用户将编辑此数据集,然后稍后将其提交以将其发送回服务器.

I have a dynamic form which shows multiple datasets I've got via REST. The user will edit this dataset and then later just submit it to get it sent back to the server.

该表单是使用FormBuilder.array()动态构建的,并通过模板中的formArrayName + *ngFor循环遍历.

The form is built dynamically with FormBuilder.array() and looped through via formArrayName + *ngFor in my template.

每个数据集的一个属性是我要显示的最新更新"信息以及表单中的可编辑数据.现在,我使用具有disabled属性的<input>字段-看起来有点难看.

One property of each dataset is a "last updated" information I want to display along with the editable data in my form. Right now I use an <input> field with disabled attribute - but this looks kinda ugly.

当我使用模型驱动的表单时,每个数据集只有一个<span>{{mf.lastUpdated}}</span>部分,可以很好地显示日期.

When I used a model driven form i just had a <span>{{mf.lastUpdated}}</span> part for each dataset which just displayed the date nicely.

现在,我想使用反应式表单,不能在<span>标记中设置formControlName-那么我应该如何在没有任何输入可能性的情况下显示信息?

Now that I want to use reactive Forms, I can't set formControlName in a <span> Tag - so how am I supposed to display the information without any input possibility?

柱塞: http://plnkr.co/edit/JZIjXH9CagJNHLxK64fG?p=preview

上次使用"字段-我想将其显示为仅文本",而没有输入标签

The "last Used" field - I want to display it as "text only" without an input-tag

推荐答案

它是一个老问题的主题,但我也面临着同样的问题

It themes an old question, but I'm facing the same problem

formControlName仅适用于输入,选择和文本区域.具有值"属性的任何内容.

formControlName only works on input, select and textarea. anything that has "value" property.

我设法直接在html中使用丑陋的解决方法

I have managed to make it work with an ugly workaround directly in the html

 {{ctrl.get("lastUpdated").value}}

  • ctrl =是ngFor内部的AbstractControl迭代器,通常是* ngFor =让FormArray.controls的ctrl;让ndx = index"

    • ctrl = is your AbstractControl iterator from inside the ngFor, typically *ngFor="let ctrl of theFormArray.controls; let ndx=index"

      lastUpdated =是要显示的字段

      lastUpdated = is the field you want to display

      这篇关于使用带有&lt; span&gt;之类的formControlName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆