AngularJS binds to dynamic model name

I have a generic JSON structure like

{
 "parameters":
              [
                {
                  "key":"fieldName","posibleValues":["Val1,"Val2"],
                  "key":"anotherField","posibleValues":["ValA,"ValB"]
                }
              ]
 }

      

No, I want to do something like this:

<div ng-repeat="parameter in parameters">
  <ng-form name="paramForm">
    {{parameter.key}}: <select ng-model="request.parameter.{parameter.key}" ng-option="..." />    
  </ng-form>


</div>

      

Problems arise with

select ng-model="request.parameter.{parameter.key}"

      

So, I want to set up a model called "request.parameter.fieldName" (according to the "key" in the JSON structure.

Is it possible? Or should I help myself with changing ng?

thank

+3


source to share


1 answer


If anyone is looking for something this way, you can use the following syntax:



request.parameter[parameter.key]

      

+4


source







All Articles