javascript - Perform an action when input meets requirements -


this question has answer here:

i'd perform action (submit form, basically) when string entered in input field reaches given length, using angular2. tried using angular2's controls didn't seem meant that.

i using jquery or vanilla javascript wondering if there more "angular2" way it.

<input type="text" value="{{userinput}}" class="form-control"> // when userinput > 3, submit form 

this framework being relatively new, cannot find solution on internet, although simple. have idea ?

thank you.

you associate control on input , subscribe on valuechanges property.

here sample:

@component({   (...)   template: `     <input type="text" value="{{userinput}}"            class="form-control"            [ngformcontrol]="ctrl">   ` }) export class somecomponent {   constructor() {     this.ctrl = new control();     this.ctrl.valuechanges           .filter((value) => {             return (value.length > 3);           })           .subscribe((value) => {             //           });   } } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -