ng-select sucks

by Marcus Baptiste

HTML

<div ng-app="app">
  <div ng-controller="ctrl">
    <p>selected Index: {{ selectedRef }}</p>
    <label>Selected: {{ writeOption() }}</label><br>
    <label>Edit Ref: {{ edit.ref }}</label>
    <select ng-if="editing" ng-model="edit.ref">
      <option ng-repeat="option in options" ng-value="option.id" ng-selected="option.id == edit.ref">{{option.name}}</option>
    </select>
    <button ng-if="!editing" ng-click="startEdit()">Edit</button>
    <button ng-if="editing" ng-click="saveEdit()">Save</button>
  </div>  
</div>

JavaScript

var app = angular.module('app', []);


app.controller('ctrl', function($scope) {
  $scope.editing = false;
  $scope.edit = {};
  $scope.options = [
  	{ id: 0, name: 'option 1'},
    { id: 1, name: 'option 2'},
    { id: 2, name: 'option 3'},
    { id: 3, name: 'option 2'}
  ];
  $scope.selectedRef = 1;
  
  $scope.startEdit = function() {
  	//$scope.edit.ref = $scope.selectedRef;
    $scope.editing = true;    
  };  

  $scope.saveEdit = function() {
  	$scope.selectedRef = parseInt($scope.edit.ref);
    $scope.editing = false;
  };
  
  $scope.writeOption = function() {
  	if (!isNaN($scope.selectedRef)) {
    	return $scope.options[$scope.selectedRef].name;
    }
  };
});