0

I want to take the input field value each time a letter is added/changed/deleted so I'm using the jquery to trigger it. but I don't know how to save this value.

in the html:

 <form [formGroup]="searchForm">
    <input id='myTextbox1' type='text'/>
  </form>

in the ts file:

searchString:string;
searchForm: FormGroup;
  ngOnInit(){

    this.searchForm =  new FormGroup({
      'str':new FormControl(null)
    })
    /
  

    $('#myTextbox1').on('input', function() {
    // i tried this:
      this.searchString = this.searchFrom.controls['str'].value
  });

    
  }

but controls weren't read from the form.

I just want to save the value of the input field in the searchstring variable and change it each time it changes. please help me.

1 Answer 1

1

Rather than using jquery you could update your code as below:

 <form [formGroup]="searchForm">
    <input id='myTextbox1' type='text' formControlName="str"/>
  </form>

and instead of the jquery code you could use the power of Observables:

 this.searchForm.str.valueChanges.subscribe((value) => {
     this.searchString = value;
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.