[英]Angularjs combo box key value
I am using Angularjs and I have a dropdown box that lists several items. 我正在使用Angularjs,并且有一个下拉列表框列出了一些项目。 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? 我该怎么办?
Try this out 试试看
html 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 = '';
}
});
You seem to want something like a tagging widget. 您似乎想要类似标签的小部件。 Maybe looking at angular-tags you can accomplish what you want 也许看一下角度标签就可以完成您想要的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.