WinDev WinDev - 11 days ago 5
AngularJS Question

Angularjs onkeypress update value from input

<td>{{count}}</td>
<td><div class="col-xs-12"><input type="text" ng-keypress="count ='10'" ng-init="count=0"></div></td>


Its working but I want to put the input text value into the count= to display the input value in the {{count}}
So if I write 20 into the input box the {{count}} must be 20 etc. But I dont know how to put the input text value into the ng-keypress without adding extra javascript parts.

Answer

Put ng-model directive on input element, That will enable two way binding and remove ng-keypress which isn't make sense there to have it.

<td>
  <div class="col-xs-12">
     <input type="text" ng-model="count" ng-init="count=0">
  </div>
</td>
Comments