【问题标题】:Model binding is not working when creating different type inputs dynamically with AngularJs ng-repeat使用 AngularJs ng-repeat 动态创建不同类型的输入时,模型绑定不起作用
【发布时间】:2013-07-11 08:36:18
【问题描述】:

请看plunkerhttp://plnkr.co/edit/TZI0xM的代码 如果输入类型是固定的(全文本或全复选框...),没有问题,数据绑定工作,但如果我动态定义输入类型,第二个输入绑定不起作用,请帮助我。

<ul>
    <li ng-repeat="prop in currentNode.props">
        {{prop.name}}<input ng-model="prop.value" type="{{prop.type}}"></input>
    </li>
</ul>

【问题讨论】:

  • 可以贴出代码,修复后数据绑定是如何工作的
  • 切换到 Angular 版本 1.1.5 就可以了
  • [固定]不是一个干净的方法,但有效。检查这个 -> plnkr.co/edit/lvFSQA?p=preview

标签: angularjs angularjs-ng-repeat ng-repeat


【解决方案1】:

好的,这里是html

<li ng-repeat="prop in currentNode.props">
        {{prop.name}}<input ng-model="prop.value" checked="{{prop.value}}" type="{{prop.type}}"></input>
    </li>

和控制器代码

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.currentNode = {name:'cube',
                        props:[
                          {name:'displayName',value:'New Cube',type:'text'},
                          {name:'visible',value:'checked',type:'checkbox'}
                        ]};
});

这里是 plunk http://plnkr.co/edit/zy5Lh9

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 2014-03-10
    • 1970-01-01
    相关资源
    最近更新 更多