Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send input value on click event

i am trying to send the value of an input field, on "onClick" of a button event, what's wrong with that?

html:

<input #new_field type="text" />
<button (click)="saveNewField(new_field.value)">Save</button>

ts

saveNewField(new_name) {
// new_name is undefined
}
like image 513
E.Meir Avatar asked Mar 07 '26 22:03

E.Meir


1 Answers

You have to define value attribute to it, otherwise, it will be recognized as undefined.

<input #new_field type="text" value=""/>
like image 154
Prachi Avatar answered Mar 09 '26 19:03

Prachi