wuno wuno - 4 days ago 6
TypeScript Question

Passing Disabled Form Input Value On Post Angular2

I have a form which has an email field. I am adding the value of the form field with

interpolation
. But I do not want the user to be able to change the email address in the form field. So I add the
disabled
flag to the
input field
. When I add
disabled
the form does not pass the email to the
http post
.

How can I disable this input field but still show the email address init to the user so that it will still post when the form is submitted with the rest of the form data?

<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>


Maybe I am confused about
two way data binding
but can I not just add the value to it with something like this,

[(ngModel)]="personal.email"
=
{{auth.userProfile.email}}


Then still keep the form input field disabled?

Answer

<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> do not use disable. if you wanna pass value then use readonly (readonly="readonly"). it will let you post the value

Comments