I have a <select> element which is rendered from an array with some vehicles in it.
When I choose a vehicle and add it to another array, I want it to not be displayed in the <select> element. However, I cannot figure out how to achieve this.
Here is my current code:
var app = angular.module('app', []);
function MyCtrl($scope) {
$scope.chosenTags = [];
$scope.tags = [
{ id: 1, name: 'Ford', type: 'Car' },
{ id: 2, name: 'Open', type: 'Car' },
{ id: 3, name: 'Ferrari', type: 'Car' },
{ id: 4, name: 'Mountain', type: 'Bike' },
{ id: 5, name: 'BMX', type: 'Bike' },
{ id: 6, name: 'Racing', type: 'Bike' },
];
$scope.currentTag = $scope.tags[0];
$scope.addTag = function() {
$scope.chosenTags.push($scope.currentTag);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="MyCtrl">
<select ng-model="currentTag" id="tags" ng-options="tag.name group by tag.type for tag in tags"></select>
<button ng-click="addTag()">Add</button>
<hr />
<div ng-repeat="tag in chosenTags">{{ tag }}</div>
</div>
</div>
And a JSFiddle for those of you who prefers that.
How can I get rid of the added vehicles in the <select> element?