title: In Angularjs to assign ng-model for dynamically and read the values in Controller function
body: <p>I am trying to create a new rectangle when the user clicks <code>add</code> button. This rectangle would also have an input field and select for these fields I am trying to assign the <code>ng-model</code> dynamically and read the corresponding values in the controller.</p>
  <p><code>HTML</code>:</p>
  <pre><code>&lt;button id=&quot;AddNewField&quot; ng-click=&quot;AddNewField();&quot; class=&quot;btn btn-success&quot;&gt; Add New &lt;/button&gt;
  &lt;div ng-repeat=&quot;(key,value) in NewFieldValues&quot;&gt;
      {{ value.ID }}
      &lt;div style=&quot;width:250px;height:100px;border:1px solid #000;&quot; draggable=&quot;true&quot;&gt;
          &lt;select ng-model=&quot;BusinessStep[value.ID]&quot; ng-change=&quot;BusinessStepChange(value.ID)&quot; class=&quot;form-control&quot;&gt;
              &lt;option ng-repeat=&quot;businessStep in businessSteps&quot; value=&quot;{{ businessStep.value }}&quot;&gt; {{ businessStep.text }} &lt;/option&gt;
          &lt;/select&gt;
          &lt;br/&gt;
          &lt;input type=&quot;text&quot; ng-model=&quot;Events[value.ID]&quot;&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p><code>Angularjs</code>:
  $scope.NewFieldValues   =   [];</p>
  <pre><code>$scope.FieldID          =   0;
  
  $scope.AddNewField  =   function(){
      item            =   {};
      item[&quot;ID&quot;]      =   $scope.FieldID;
      item[&quot;Fields&quot;]  =   [];
      $scope.NewFieldValues.push(item);
      $scope.FieldID++;
  }
  
  $scope.BusinessStepChange   =   function(BusinessStepID){
      
      for(var bs=0; bs&lt;$scope.NewFieldValues.length; bs++)
      {
          if($scope.NewFieldValues[bs].ID ==  BusinessStepID)
          {
              console.log($scope.NewFieldValues[bs]);
              console.log($scope.BusinessStep);
              $scope.NewFieldValues[bs]['Fields'].BusinessStep    =   &quot;Hello&quot;; //Read the value from corresponding select field
          }
      }       
  }
  </code></pre>
  <p>How can I assign the <code>ng-model</code> field dynamically for each field in the rectangle and also how can I read them in the controller function</p>