Skip to content

Binding on input [type] is broken #13243

@GuyShaanan

Description

@GuyShaanan

I'm submitting a ...

[x] bug report => search github for a similar issue or PR before submitting

Current behavior
Try to bind the type attribute of input:

// in Class
inputType="number"

// in html
<input [type]="inputType" formControlName="integerB" />

Initially, the value is presented as number when doing form.value:

{"integerB": 5}

Now, try to change the input's value.

Its type has changed to string:

{"integerB": "5"}

while it seems the html attributes haven't changed:

// chrome dev console
<input formcontrolname="integerB" ng-reflect-name="integerB" ng-reflect-type="number" type="number" class="ng-valid ng-dirty ng-touched">

Expected behavior
If we are able to bind to [type], the input type should have stayed "number", so does the value.

Minimal reproduction of the problem with instructions
http://plnkr.co/edit/kp0xoDbZmJnD5orOTZUj?p=preview

What is the motivation / use case for changing the behavior?
I'm dynamiclly generating forms from given JSON, so binding to [type] can save a lot of copy-paste code.

Please tell us about your environment:
Not sure this is relevant as it is reproducible in plnkr.

Thanks.

Edit: same goes if binding [type] to inputType="checkbox".
Edit2: this is also broken in the Dynamic Forms demo if you change "email" type to number (for example)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions