3

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.

2
  • Try ng-value not value maybe. Commented Jan 23, 2015 at 11:51
  • @Zyga doesn't work too... Commented Jan 23, 2015 at 12:01

2 Answers 2

5

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/

Sign up to request clarification or add additional context in comments.

8 Comments

After I put copy-field under ng-model field in html it works.... But is there any way to put copy field before ng-model? Is order so important?
@Anton Abramov Sorry, not sure what u mean? If you ask about the order of input elements in the DOM then it shouldnt matter no.
I mean when i try to fill first field, value copies to second. But if i try to fill second field, first doesn't change
@Anton Abramov If you use ng-value for second then it wont change. But you can put ng-model in both which will work then. But I though the second element will be hidden anyway so you wont be able to input anything?
Funny thing - actually in my project hidden field will be in form(right now it's not hidden for testing). Ng-model field will be under the form in div. So in that order field in form empty if i fill field in div, but if i fill form-field div-field will change value.
|
0

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

1 Comment

Sorry, but problem is not about hiding. I use type="text" here for example. Problem is about copy value from one field to another

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.