我有一个带有电子邮件字段的表单。我正在使用 interpolation
添加表单字段的值。但我不希望用户能够更改表单字段中的电子邮件地址。所以我添加 disabled
标记为input field
。当我添加disabled
时该表单不会将电子邮件传递至 http post
.
如何禁用此输入字段,但仍向用户显示电子邮件地址初始化,以便在提交表单和其余表单数据时它仍会发布?
<input type="text" class="form-control" id="email"
[(ngModel)]="personal.email" name="email" #email="ngModel" required
value="{{auth.userProfile.email}}" placeholder="{{auth.userProfile.email}}" disabled>
也许我对 two way data binding
感到困惑但我不能只是用这样的东西来增加值(value)吗,
[(ngModel)]="personal.email"
=
{{auth.userProfile.email}}
那么仍然禁用表单输入字段吗?
最佳答案
<input type="text" class="form-control" id="email"
[(ngModel)]="personal.email" name="email" #email="ngModel" required
value="{{auth.userProfile.email}}" placeholder="{{auth.userProfile.email}}" readonly>
不要使用禁用。
如果你想传递值,那么使用只读(readonly =“readonly”)。
它会让你发布值
关于javascript - 在 Angular2 后传递禁用表单输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40858537/