javascript - Perform an action when input meets requirements -
this question has answer here:
- how watch form changes in angular 2? 4 answers
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
Post a Comment