title: ng-keypress to call function in angularjs
body: <p>I have send button and I click on that button I send text from input. I want also on enter keyboard to send that text. I try with two solutions and nothing..</p>
  <p>You can find my code below:</p>
  <p><strong>First Solution</strong></p>
  <pre><code>&lt;div class=&quot;modal-footer&quot;&gt;
                  &lt;input id=&quot;enterText&quot; name=&quot;enterText&quot; class=&quot;form-control&quot; aria-describedby=&quot;basic-addon1&quot;
                         ng-model=&quot;modalInstanceController.showText&quot; ng-keypress=&quot;keyEnter($event)&quot;&gt;
                  &lt;br/&gt;
                  &lt;button class=&quot;btn btn-primary&quot; type=&quot;button&quot; ng-click=&quot;modalInstanceController.concatConversation()&quot;
                          ng-keypress=&quot;$event.which === 13 &amp;&amp; modalInstanceController.concatConversation()&quot;&gt;Send
                  &lt;/button&gt;
          &lt;/div&gt;
  </code></pre>
  <p><strong>Second solution</strong></p>
  <p>With send button I call this function:</p>
  <pre><code> $scope.modalInstanceController.concatConversation = function () {
  
              $scope.modalInstanceController.currentConversation.push({
                  loggedUser: $scope.modalInstanceController.showText,
                  user: 'typing...'
              });
              $scope.modalInstanceController.showText = &quot;&quot;;
  
          };
  </code></pre>
  <p>I also try to call this function in <code>keyEnter</code> function:</p>
  <pre><code>$scope.modalInstanceController.keyEnter = function (keyEvent) {
              if (keyEvent.which === 13) {
                  $scope.modalInstanceController.currentConversation.push({
                      loggedUser: $scope.modalInstanceController.showText,
                      user: 'typing...'
                  });
                  $scope.modalInstanceController.showText = &quot;&quot;;
              }
          };
  
  $scope.modalInstanceController.keyEnter();
  </code></pre>
  <p>And in html:</p>
  <pre><code>&lt;button class=&quot;btn btn-primary&quot; type=&quot;button&quot; ng-click=&quot;modalInstanceController.concatConversation()&quot;
                          ng-keypress=&quot;modalInstanceController.keyEnter($event)&quot;&gt;Send
                  &lt;/button&gt;
  </code></pre>
  <p>I am getting error:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'which' of undefined</p>
  </blockquote>
  <p>Should I add something on dependency or what?</p>