One reason for this behavior is due to ng-repeat creating a child scope that inherits prototypically from the container scope. If you're unfamiliar with this concept, do some research online, as there are plenty of explanations available.
Alternatively, you can refer to: https://github.com/angular/angular.js/wiki/Understanding-Scopes
To get a deeper understanding of what's happening, consider installing Angular Batarang in Chrome to inspect the scopes.
A cleaner approach to dealing with this issue is to use controllerAs like so:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl as vm">
<ul>
<!--Inside ng-repeat-->
<li ng-repeat="x in vm.d">
{{$index}} <input ng-model="vm.val">{{vm.val}}
</li>
<!--Inside ng-repeat-->
<br><br><br>
<!--Outside ng-repeat-->
Outer<input ng-model="vm.val">{{vm.val}}
<!--Outside ng-repeat-->
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope) {
this.d=[1,2,3,4,5];
});
</script>
</body>
</html>
Detailed Explanation
Think of scopes in this simplistic way:
function ParentScope(){
this.val = "parent";
}
function ChildScope(){
}
ChildScope.prototype = new ParentScope();
ChildScope.prototype.constructor = ChildScope;
var childScope = new ChildScope();
Explaining your scenarios:
1: Typing in an ng-repeated textbox causes ng-model to update the "val" property in the childScope, which actually exists in the prototype chain of the object.
childScope.val = "child"
This action creates a new property on the child object, hiding the parent property.
3: Typing in the text box outside ng-repeat changes the "val" in Parent Scope. Since child scopes inherit from the parent scope, they can access this property, causing all ng-repeated text boxes to display the same value. However, typing in an ng-repeated text box again tries to update the child scope, creating a new property and hiding the parent property once more.
I hope that clarifies things for you.