javascript - Validation based on keypress in angular 2 -
i trying simple number validation angular2 project. unable replicated javascript code written below.
html
<input type="text" class="textfield" value="" id="extra7" name="extra7" onkeypress="return isnumber(event)" />
javascript
function isnumber(evt) { evt = (evt) ? evt : window.event; var charcode = (evt.which) ? evt.which : evt.keycode; if (charcode > 31 && (charcode != 46 && (charcode < 48 || charcode > 57))) { return false; } else { return true; } }
now angularjs2 when tried return isnumber(event)
unable compile html file. , firing rx.js error. if remove return
compiled not work should.
am missing in terms of angularjs2 world.
please let me know if further details required.
update
this way doing in angular2. here can keypress if remove return keyword can't use whatever returning isnumber method.
ps: doing special work because firefox input type number check number @ time of form post. , angularjs2 bypassing form post (full html post) give ajax post afaik.
when binding function element should have football operator:
<input ... (keypress)="return isnumber()"/>
if doesn't work, curious why need return function on keypress...
Comments
Post a Comment