APP.directive('miloMatchEntity', function() {
	return {
		scope: {
			entityEndpoint: '=miloMatchEntity',
			entityName: '=?miloEntityName',
			entityId: '=?miloEntityId',
			ngModel: '='
		}, controller: ['$scope', '$element', '$attrs', 'GlobalService', function($scope, $element, $attrs, GlobalService) {
			var matchEntity = function (instances) {
				for (var i = 0; instances && i < instances.length; i ++) {
					if ($scope.ngModel && instances[i][$scope.entityId] === $scope.ngModel[$scope.entityId]) {
						$scope.ngModel = instances[i];
					}
				}
			};
			var scope = $element.scope();
			if (! scope.miloSelectData) {
				scope.miloSelectData = {};
			}
			if (! $scope.entityName) {
				$scope.entityName = 'name';
			}
			if (! $scope.entityId) {
				$scope.entityId = 'id';
			}
			if (! scope.miloSelectData[$scope.entityEndpoint]) {
				GlobalService.getEntityInstances($scope.entityEndpoint).$promise.then(function (data) {
					scope.miloSelectData[$scope.entityEndpoint] = data;
					scope.miloSelectData[$scope.entityEndpoint].unshift({});
					matchEntity(scope.miloSelectData[$scope.entityEndpoint]);
				});
			} else {
				matchEntity(scope.miloSelectData[$scope.entityEndpoint]);
			}
			$attrs['ngOptions'] = 'value.' + $scope.entityName + ' for value in miloSelectData["' + $scope.entityEndpoint + '"]';

			$scope.$watch('ngModel', function () {
					matchEntity(scope.miloSelectData[$scope.entityEndpoint]);
			});
    	}]
	};
});

@@ -946,59 +946,207 @@
 %09%09%09%09
-scope.miloSelectData%5B$scope.entityEndpoint%5D = data;
+if (data && data.length) %7B // add empty line at the beginning%0A%09%09%09%09%09%09delete data%5B0%5D%5B'$$hashKey'%5D;%0A%09%09%09%09%09%09if (JSON.stringify(data%5B0%5D) != '%7B%22name%22:%22%22%7D') %7B%0A%09%09%09%09%09%09%09data.unshift(%7B%22name%22:%22%22%7D);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D
 %0A%09%09%09
@@ -1194,20 +1194,15 @@
 int%5D
-.unshift(%7B%7D)
+ = data
 ;%0A%09%09

fix match entity directive empty line