title: dynamically bind input value to select list by its JSON data 'id'
body: <p>I'm working with some fairly complicated data (simplified somewhat below). Here I have a list of selector lists, each with an <code>id</code> specified in its JSON data. I then have a list of texts which need to bind a specified field (I've got that bit sorted) in a specified (via the text's <code>listid</code>) selector list (haven't got that bit sorted).</p>
  
  <p>This is what my data in the js controller file looks like:</p>
  
  <pre><code>angular.module('myApp',[])
  .controller('myCtrl',function($scope,$timeout){
      $scope.selectorLists=[
          {
              'id': 3,
              'name': 'SelectionList ABC',
              'rows': [
                  {'id':5, 'name':'ABCrow 5', 'Afield1': 'ABCrow5field1', 'Afield2': 'ABCrow5field2'}, 
                  {'id':9, 'name':'ABCrow 9', 'Afield1': 'ABCrow9field1', 'Afield2': 'ABCrow9field2'}
               ]
          },
          {
              'id': 5,
              'name': 'SelectionList XYZ',
              'rows': [
                  {'id':1, 'name':'XYZrow 1', 'Xfield1': 'XYZrow1field1', 'Xfield2': 'XYZrow1field2'}, 
                  {'id':2, 'name':'XYZrow 2', 'Xfield1': 'XYZrow2field1', 'Xfield2': 'XYZrow2field2'}
               ]
          }
      ];
  
      $scope.texts=[
          {'id': 453,
           'name': 'Input Text1',
           'listid': 3,
           'listrowid': 9,
           'listfieldname': 'Afield1'
          },
          {'id': 454,
           'name': 'Input Text2',
           'listid': 5,
           'listrowid': 2,
           'listfieldname': 'Xfield2'
          }
      ];
  
  });
  </code></pre>
  
  <p>And this is what the html looks like:</p>
  
  <pre><code>&lt;div ng-app="myApp" ng-controller="myCtrl"&gt;
  
      &lt;div ng-repeat='selectionList in selectorLists'&gt;
          &lt;label for="ddl{{selectionList.id}}"&gt;{{selectionList.name}}:&lt;/label&gt;
          &lt;select id="ddl{{selectionList.id}}" ng-model="selectionList.selectedRow"                 
                  ng-options="row as row.name for row in selectionList.rows" &gt;&lt;/select&gt;
      &lt;/div&gt;
  
      &lt;div ng-repeat='text in texts'&gt;
          &lt;label for='txt{{text.id}}'&gt;{{text.name}}&lt;/label&gt;
          &lt;input type="text" id='txt{{text.id}}' value='{{selectorLists[id=text.listid].selectedRow[text.listfieldname]}}'   /&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I can use a <code>$filter</code> in my controller and get the right list there, but I need to get it to bind its selected value to my text input (by passing in <code>text.listid</code>).</p>
  
  <pre><code>    var listid = 5;
      var result = $filter('filter')($scope.selectorLists, {id:listid})[0];
  </code></pre>
  
  <p>I also need to be able to initialise a selected value in the selector lists, either by cycling through my texts and coming across the first <code>listid</code> that references the list, <em>and</em> has a <code>listrowid</code> set (i.e. to any value > 0; 0 defines none is selected for that text), or by doing that server-side and just setting a <code>selectedRowId</code> (or, better yet, set the <code>selectedRow</code>) in each selector list. I'm just not sure how to use either way to set the selected item in the html <code>select</code> objects. </p>
  
  <p>As I'm completely new to angularjs, just a nudge in the right direction would be much appreciated.</p>
  
  <p>Oh, yes, and <a href="http://jsfiddle.net/e0ju8vqe/4/" rel="nofollow">here's the fiddle</a>.</p>