old_contents: 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]);
  			});
      	}]
  	};
  });
  
new_contents: 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) {
  					if (data && data.length) { // add empty line at the beginning
  						delete data[0]['$$hashKey'];
  						if (JSON.stringify(data[0]) != '{"name":""}') {
  							data.unshift({"name":""});
  						}
  					}
  					scope.miloSelectData[$scope.entityEndpoint] = data;
  					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]);
  			});
      	}]
  	};
  });
  
subject: fix match entity directive empty line