1

I have property fields that contains string array:

in controller I have:

$scope.data = {};

$scope.fields = [
    "new0.name",
    "new0.type",
    "new0.address",
    "new0.city",
    "new0.postalCode"
];

in view I have:

  <div class="control-group" ng-repeat="f in fields">
    <label class="control-label">Some field name</label>
    <div class="controls">
      <input type="text" name="{{f}}" ng-model="data.f" class="input-xlarge">
    </div>
  </div>

In the ng-repeat, how can I concatenate value of f to the ng-model to get, for example ng-model="data.new0.name"?

3
  • 3
    Ignore my answer below, have you tried data[f] Commented Nov 21, 2013 at 15:51
  • @tymeJV data[f] is solution. Thanks! Commented Nov 21, 2013 at 15:57
  • 1
    Posted a quick answer, was making it way too complicated at first :) Commented Nov 21, 2013 at 15:57

1 Answer 1

2

To reference a property of an object with a variable, use bracket notation

data[f]
Sign up to request clarification or add additional context in comments.

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.