lascoff
lascoff

Reputation: 1331

Angularjs combo box key value

I am using Angularjs and I have a dropdown box that lists several items. If the item the user needs is not in the list I need to allow the user to enter the data. Is this possible? How would I do it?

Upvotes: 1

Views: 389

Answers (2)

Nidhish Krishnan
Nidhish Krishnan

Reputation: 20751

Try this out

Working Demo

html

<div ng-app="myapp">
    <fieldset ng-controller="FirstCtrl">
        <select ng-options="p.name for p in people" ng-model="selectedPerson"></select>

        <br>
            Name:<input type="text" ng-model="name"/>
            <button ng-click="add(name)">Add</button>
    </fieldset>
</div>

script

var myapp = angular.module('myapp', []);
myapp.controller('FirstCtrl', function ($scope) {
    $scope.people = [{
        name: 'John'
    }, {
        name: 'Rocky'
    }, {
        name: 'John'
    }, {
        name: 'Ben'
    }];

    $scope.add = function(value)
    {
        var obj= {};
        obj.name = value;        
        $scope.people.push(obj); 
        $scope.name = '';
    }
});

Upvotes: 1

TKrugg
TKrugg

Reputation: 2405

You seem to want something like a tagging widget. Maybe looking at angular-tags you can accomplish what you want

Upvotes: 0

Related Questions