title: Attempting to track row of textarea with ng-keypress
body: <p>*Note, the line wraps don't matter to me, I need the line number based on the number of new line characters, because I am going to split vm.text in the future and access it like an array.</p>
  
  <p>I want to know what row of a text area I'm on, every time I hit the enter key. I followed the answer from here: 
  <a href="https://stackoverflow.com/questions/9185630/find-out-the-line-row-number-of-the-cursor-in-a-textarea">Find out the &#39;line&#39; (row) number of the cursor in a textarea</a></p>
  
  <p>And I attempted to merge it with ng-keypress like so:</p>
  
  <p>enmasse.html</p>
  
  <pre><code>&lt;form role="form" ng-submit="vm.submit()"&gt;
  &lt;div class="form-group"&gt;
      &lt;h2 layout="column" layout-align="center center"&gt;Multi-Event Creation&lt;/h2&gt;
      &lt;br&gt;
  
      &lt;div&gt;Input Formats&lt;/div&gt;
      &lt;!-- display input 'rulebook' here --&gt;
      &lt;br&gt;
      &lt;md-input-container&gt;
          &lt;label style="color:#545454"&gt;Enter your events/tasks, line by line&lt;/label&gt;
          &lt;textarea cols="50" ng-keypress="vm.check(this, $event.keyCode)" ng-model="vm.text" required&gt;&lt;/textarea&gt;
      &lt;/md-input-container&gt;
  
      &lt;div class="form-group" layout="column" layout-align="center center"&gt;
          &lt;md-button class="md-raised md-primary btn-submit" type="submit"&gt;Submit&lt;/md-button&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Note, I am using ngDialog to connect my controller to my form.</p>
  
  <p>enmasse-controller.js</p>
  
  <pre><code>(function () {
  'use strict';
  
  angular
      .module('app.enmasse.controllers')
      .controller('EnmasseController', EnmasseController);
  
  EnmasseController.$inject = ['$rootScope', '$scope', 'Authentication', 'Snackbar', 'Posts', 'Access'];
  
  function EnmasseController($rootScope, $scope, Authentication, Snackbar, Posts, Access) {
      var vm = this;
      vm.submit = submit;
      vm.check = check;
      vm.lineNumber;
  
      function check(textarea, keyCode) {
          //console.log(keyCode); *works
  
  // trouble in this section
          if (keyCode == 13) {
              vm.lineNumber = textarea.value.substr(0, textarea.selectionStart).split("\n").length;
              console.log(vm.lineNumber);
          }
  //
  
          //if (keyCode==13) {
          //console.log(vm.text); *works for pulling all text in textarea, but need to pull the previous line!
          //validate();
          //}
      }
  
      function submit() { //called when all the lines are validated and user clicks submit
      }
  }
  })();
  </code></pre>
  
  <p>The browser console is throwing the following error at me --> TypeError: Cannot read property 'substr' of undefined</p>
  
  <p>How can I get around this?</p>