0

I have a object I have iterated using ng-repeat and while iterating I want to add each field to another object through ng-model.

//html 

<div ng-repeat="field in forms.fields track by $index">
    <span ng-if="field.type=='textbox'">
    <span style="width:115px;text-transform: capitalize" class="col-lg-5">{{field.Name}}</span>
    <input type="text" class="form-control" style="width: 172px;padding-left: 20px;display: inline-block;" ng-class="{mystyle:field.Name.$invalid}" id="inp_{{$index}}" ng-model="inputfields.{{field.Name}}">{{field.Name}}<br>
</span></div>

In the above code i want to assign field.Name as a property to input field which is declared as a $scope.inputfield={} in js file. So i am getting an error as

 Syntax Error: Token '{' invalid key at column 2 of the expression [{{inputfield.field.Name}}] starting at [{inputfield.field.Name}}].

So can anyone solve this please.

1
  • 2
    Try inputfields[field.Name] Commented Nov 6, 2015 at 4:47

3 Answers 3

1

try:

ng-model="inputfields[field.Name]"
Sign up to request clarification or add additional context in comments.

Comments

1

use with array notation to get the property of the object

ng-model="inputfields[field.Name]"

instead of

ng-model="inputfields.{{field.Name}}"

Comments

1
inputfields.{{field.Name}} is invalid expression assignment.

You can assign fidlename to inputfields using ng-model="inputfields[field.Name]"

for more detail refer this link : https://docs.angularjs.org/error/ngModel/nonassign

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.