Ng-repeat with dynamic ng-model on input not working

后端 未结 2 1118
借酒劲吻你
借酒劲吻你 2021-01-23 17:06

In controller I\'ve a list like this:

scope.data = [ { user: { address: { city: \'Boston\'} } } ];

And a property, where I\'ve the name to acce

相关标签:
2条回答
  • 2021-01-23 17:51

    You can do it like this because of ng-repeat:

    <input ng-model="item.user.address.city" />
    

    So you do not need to declare this:

    $scope.propertyName = 'address.city';
    

    Demo

    0 讨论(0)
  • 2021-01-23 17:53

    You can create a directive with compile, to set ng-model indirectly:

    compile: function(el, attrs) {
          return function(scope, el) {
            el.attr('ng-model', attrs.ngModelItem + '.' + scope[attrs.ngModelRef]);
            $compile(el)(scope);
          };
        }
    

    please look my sample on jsbin:

    http://jsbin.com/xizucu/edit?html,js,output

    0 讨论(0)
提交回复
热议问题