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 Answer
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.