Angularjs:改变输入类型动态 [英] Angularjs: change input type Dynamically

查看:158
本文介绍了Angularjs:改变输入类型动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时有真正值的列表。当我使用 NG-重复显示与内部的&LT值列表;输入类型=文本> ,我想有<输入类型=复选框方式> 如果该值的布尔匹配

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 ?

小提琴

编辑:,因为我没有输入这不是重复 键入 $范围变量。

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

推荐答案

只要你可以定义的 ngShow ngHide

FIDDLE

编辑FIDDLE

如果你想用表演;

<div class="form-group">
    <input type="checkbox" ng-show="parameter_list[$index].value==false || parameter_list[$index].value==true " ng-model="parameter_list[$index].value" class="form-control">
    <input type="text" ng-show="parameter_list[$index].value!=false && parameter_list[$index].value!=true " ng-model="parameter_list[$index].value" class="form-control">
</div>

或者你也可以用器isChecked 值发送对象。

<div class="form-group">
    <input type="checkbox" ng-show="parameter_list[$index].isChecked" ng-model="parameter_list[$index].value" class="form-control">
    <input type="text" ng-show="!parameter_list[$index].isChecked" ng-model="parameter_list[$index].value" class="form-control">
</div>

这篇关于Angularjs:改变输入类型动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆