javascript - 在 Angular2 后传递禁用表单输入值

标签 javascript angular typescript

我有一个带有电子邮件字段的表单。我正在使用 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/

相关文章:

javascript - TypeScript:在没有显式返回类型的情况下,不会在 lambda 中检查多余的属性

javascript - 在 jQuery 中将函数作为参数传递?

javascript - 如何修复 Angular Material Components 的构建错误?

typescript - azure-devops-扩展-api (sdk) : APIs error when using in pipeline extension

javascript - 从接口(interface)以编程方式创建 Typescript 用户定义的类型保护

javascript - 有没有办法在jquery中检查div id和类

javascript - 使用 Regex 解析 C 风格的注释,避免回溯

javascript - 如何将 Angular 7 应用程序包含在现有的 html 文件和网站中?

javascript - Ng2-Charts Linechart 仅显示前 2 个值

javascript - typescript 定义 : same name but different types inside and outside module?