Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 - Add a value to input

Tags:

angular

I tried to put the value to <input value="{{ val }}"> but I think its wrong because it returns empty data.

How can I set a default value to an input?

I already created API for update. I just really need to return the input data.

thanks

like image 286
edizonv Avatar asked Sep 07 '17 23:09

edizonv


People also ask

What is Keyup enter in Angular?

(keyup. enter) event is used to generate event when Enter key is pressed.

What does @input do in Angular?

Use the @Input() decorator in a child component or directive to let Angular know that a property in that component can receive its value from its parent component. It helps to remember that the data flow is from the perspective of the child component.

What is event target value in Angular?

The target event determines the shape of the $event object. If the target event is a native DOM element event, then $event is a DOM event object, with properties such as target and target. value . In the following example the code sets the <input> value property by binding to the name property.


2 Answers

You can use one-way input binding:

<input [value]="val">

or two-way input binding:

<input [(ngModel)]="val">

One-way will give you the value, and update it when the component updates it... but will not change the value with user input.

Two-way will change on user input as well as component changes.

like image 149
Z. Bagley Avatar answered Oct 10 '22 10:10

Z. Bagley


use this. It will show the data as well as do a two way binding. you can change its value from code to view and from view to code.

<input [(ngModel)]="val">
like image 22
Aniruddha Das Avatar answered Oct 10 '22 11:10

Aniruddha Das