0

Could anyone explain why in this http://codepen.io/mikeward/pen/gwcjt case focus lost anytime when char is typed, but in this http://codepen.io/anon/pen/fcrdh case everything works fine ?

1

1 Answer 1

0

It's because the second example uses an object instead of an integer to bind the model to the view.

The model is binded to the scope of ng-repeat by reference and when the reference changes, the ng-repeat rerenders that model - so deletes the old element and creates a new.

Integers are stored by value, so basically when you change an integer, it becomes a completely new model (as a place in memory). But when you are using objects, the reference to that object remains the same when you change only the value of some of its properties.

So as a simple explanation, the element loses focus in the first example, because it's not the same element anymore.

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

Comments

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.