javascript - How can I add a new object in a Angularjs table using ENTER (key from keyboard)? -


i have shopping list app built in angularjs works fine. can add , delete items it. issue want allow app add new items table using (event.which = 13) meaning using "enter" key keyboard. when user on input text field , after typing item , pressing enter want new item added in table. think i'm close accomplish , user need this: type text in input field , press enter , click anywhere outside table in order add new item, wouldnt right way add new item. please on , let me know i'm doing wrong. lot in advance.

codepen: http://codepen.io/henrygranados/pen/bjwzkp

here's code:

 $("#keypresser").keypress(function(e){     var codigo = e.which;     var item   = document.getelementbyid("keypresser").value;     if(codigo == 13){          $scope.addnewitem(item);         console.log("hello");     }  }); 

use ngkeypress

html

<input ng-keypress="pressed($event,newitem)" placeholder = "enter item here..."class="form-control" ng-model="newitem"/> 

js

  $scope.pressed = function($event,item) {     if ($event.which === 13)       {$scope.addnewitem(item);       console.log("hello");}   } 

codepen

n:b: don't use jquery in controller. it's not practice.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -