0

I am working on a form builder application in Angular and have run into an odd bug in Chrome. I am dynamically setting a form input type based on a variable. This seems to work for all input types except for "file", which will always change to "text" in Chrome. A simple example is below:

<div ng-app="app">
  <input type="{{'file'}}" /><br />
  <input type="{{'color'}}" /><br />
  <input type="{{'button'}}" value="button" />
</div>

jsfiddle

1
  • Yep,You should definetly file an issue on github,this is a serious bug.And since angular folks work at Google i'm pretty sure they can have that bug fixed.Maybe a ng-type directive could fix that(like ng-src or ng-href ). Commented May 29, 2014 at 19:52

2 Answers 2

5

Indeed, it sounds like a bug, but you can easily bypass it using ngAttr:

<input ng-attr-type="{{'file'}}" />
<input ng-attr-type="{{'color'}}" />
<input ng-attr-type="{{'button'}}" value="button" />
Sign up to request clarification or add additional context in comments.

2 Comments

nice,i didnt know ng-attr !
That worked! Thanks. I also went ahead and filed an issue on github: github.com/angular/angular.js/issues/7632
0

I propose a basic version of ng-type directive :

angular.module('ng').directive('ngType', function ($timeout) {
    return {
        scope: {
            ngType: "="
        },
        link: function ($scope, element, attr) {
            $scope.$watch('ngType', function (newValue, old) {
                element.attr('type', newValue);
            });
        }
    };
});

http://jsfiddle.net/camus/x649Q/2/

while the "bug" get fixed.

EDIT : blackhole answer is the right one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.