0

I have used this post to crate binding:

Angular HTML binding

but messed up with an error:

Property 'value' does not exist on type 'EventTarget'.

Wherе might be the point?

html: <input [value]="test" (input)="test = $event.target.value">

"test" is a property of a component.

Question might be stupid, but I have tested different ways to solve the problem and see no way out. Thanks for any help.

1
  • Import the FormsModule in the module declaring the component, and try using <input [(ngModel)]="test"> instead Commented Jul 16, 2022 at 17:22

1 Answer 1

2
<input [value]="test" (input)="onInput($event)">
onInput(event: Event) {
  this.test = ($event.target as HTMLInputElement).value;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Excuse me, but how could I bind two elements this way? I mean, what if I want to hang the function on button element, and get value param of input? <input [value]="test"> <button (click)="onInput()>
Like this: <input #someName [value]="test"> <button (click)="onInput(someName.value)">

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.