Anton Abramov
Anton Abramov

Reputation: 2331

AngularJS copy value to another input on fly

I need to bind 1 model to 2 inputs. First input should be visible and i use it to set value to model

<input type="text" ng-model="ttl" class="form-control input-sm"/>

Second input hidden and i use it for form. I need to keep here actual value of model

<input type="text" name="ttl" value="{{ttl}}" class="form-control input-sm"/>

The problem is hidden input always empty.... How to fix it? Thanks.

Upvotes: 3

Views: 6084

Answers (2)

squiroid
squiroid

Reputation: 14017

Simple use ng-model on both:-

 <input type="text" ng-model="ttl" class="form-control input-sm"/>
    <input type="text" name="ttl" ng-model="ttl" class="form-control input-sm"/>

Plunker:- http://plnkr.co/edit/fzCaGgqRmvV9UogzzTWk?p=preview

Upvotes: 0

Zyga
Zyga

Reputation: 2417

This seems to work for me (second input box only below):

<input type="text" name="ttl" ng-value="ttl" class="form-control input-sm"/>

or

<input type="text" name="ttl" ng-model="ttl" class="form-control input-sm"/>

I understand that you will hide that input yourself?

JSFiddle:

http://jsfiddle.net/66chbuon/

Upvotes: 5

Related Questions