controller.js
/* Example Select2 & AngularJs */ $scope.noResultsTag = null; $scope.tags = [ {id: 0, name: "Zero"}, {id: 1, name: "One"}, {id: 2, name: "Two"}, {id: 3, name: "Three"}, {id: 4, name: "Four"}, ]; $scope.select2Options = { formatNoMatches: function(term) { console.log("Term: " + term); var message = 'Add tag:"' + term + '"'; if(!$scope.$$phase) { $scope.$apply(function() { $scope.noResultsTag = term; }); } return message; } }; //$scope.selectedTags = [1,4]; $scope.addTag = function() { $scope.tags.push({ id: $scope.tags.length, name: $scope.noResultsTag }); }; /* End : Example Select2 & AngularJs */html code
<select multiple="" ng-model="selectedTags" style="width: 400px;" ui-select2="select2Options"> <option ng-repeat="tag in tags" value="{{tag.id}}">{{tag.name}}</option> </select>js lib include
<script src="https://rawgithub.com/angular-ui/ui-select2/master/src/select2.js"></script>