title: Get selected row of angularjs ui-grid
body: <p>I've looked at multiple articles on this ui-grid and its giving me fits.  I'm trying to get the selected row object.  I'm either getting an undefined or can not read property of 'getSelectedRows'.  Any help is greatly appreciated.</p>
  
  <p>I started with this article <a href="https://stackoverflow.com/questions/26188565/where-can-i-get-angular-ui-grid-selected-items">here</a> and the documentation doesnt seem to be all that great either.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>        vm.gridOptions = {
          enableRowSelection: false,
          enableSelectAll: false,
          showGridFooter:true
  
      };
  
      vm.gridOptions.columnDefs = [
          { name: 'productName' },
          { name: 'unitPrice' }
      ];
  
      vm.gridOptions.multiSelect = false;
  
      vm.getSelectedRows = function () {
          vm.mySelectedRows = vm.gridApi.selection.getSelectedRows();
      }
  
       productDataService.getProductList()
           .then(function (result) {                 
               vm.gridOptions.data = result.data;
               vm.mySelectedRows = vm.gridApi.selection.getSelectedRows();&lt;--Property undefined error here
               $timeout(function() {
                   if (vm.gridApi.selection.selectedRow) {
                       vm.gridApi.selection.selectRow(vm.gridOptions.data[0]);
                   }
               });
           });
  
      vm.gridOptions.onRegisterApi = function(gridApi) {
          vm.gridApi = gridApi;
      }
  </code></pre>