Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs: change input type Dynamically

Tags:

html

angularjs

I have a list which sometimes has true or false value. When I'm using ng-repeat to show the list with the value inside an <input type="text"> , I'd like to have <input type="checkbox"> if the value matches a boolean.

<table class="table table-hover table-striped table-bordered">
    <tbody>
        <tr ng-repeat="parameter in parameter_list">
            <th class="text-left">
                {{parameter.title | uppercase}}
            </th>
            <td class="text-left">
              <div class="form-group">
                <input type="text" ng-model="parameter_list[$index].value" class="form-control">
              </div>
            </td>
        </tr>
    </tbody>
</table>

Any ideas, how can I achieve this ?

Fiddle

Edit : It's not a duplicate since I don't have the input type in a $scope variable.

like image 261
AshBringer Avatar asked Mar 08 '16 08:03

AshBringer


1 Answers

Just keep it simple:

<input type="{{typeInput}}" />

And in your controller:

$scope.typeInput = 'number';

Works like a charm, without all that extra code

like image 117
Oscar Bout Avatar answered Oct 20 '22 06:10

Oscar Bout