Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 - get input value

I would like to know how to get the value from an input on angular 4. I looked over the documentation on angular and the example with the key event doesn't work very well for me and I can't find a proper example how to do this so please help me out

The problem: I try to read the input's value and after submiting the value to another component that will add the value to a select tag(e.g. send the name of the person to a list for a select tag)

My code

like image 437
Daniel Bisceanu Avatar asked Nov 28 '17 10:11

Daniel Bisceanu


People also ask

How to bind value to input in Angular?

[value]=“username” - Binds the expression username to the input element's value property. (input)=“expression” - Is a declarative way of binding an expression to the input element's input event (yes there's such event) username = $event. target.

What is input () in Angular?

@Input() and @Output() allow Angular to share data between the parent context and child directives or components. An @Input() property is writable while an @Output() property is observable.


2 Answers

<form (submit)="onSubmit()">    <input [(ngModel)]="playerName"> </form>  let playerName: string; onSubmit() {   return this.playerName; } 
like image 188
yala ramesh Avatar answered Sep 21 '22 12:09

yala ramesh


In HTML add

<input (keyup)="onKey($event)"> 

And in component Add

onKey(event) {const inputValue = event.target.value;} 
like image 44
laiju Avatar answered Sep 20 '22 12:09

laiju