简体   繁体   中英

create a editabale drop down in angularjs

How I can create an editable drop down, that user can add a new option inside that with filling that.

You can find my html drop down code in below:

<select class="fieldDropdown" ng-model="currentFileGroup" title=""
 ng-options="value.ls_ItemValue as value.ls_ItemText for (key, value) in formLIST.filesGroup" 
data-style=""></select>

I want when a user filled the option, it automatically added to the database. There is no problem to using JavaScript, AngularJS or jQuery.

I usually use ui-select for this sort of interaction: https://github.com/angular-ui/ui-select

The 'tagging' feature probably gets closest to what you'd want in this case: http://plnkr.co/edit/m1SQXUxftBLQtitng1f0?p=preview

<ui-select tagging="tagTransform" ng-model="person.selected" theme="bootstrap" ng-disabled="disabled" style="width: 800px;" title="Choose a person">
   <ui-select-match placeholder="Select person...">{{$select.selected.name}} &lt;{{$select.selected.email}}&gt;</ui-select-match>
   <ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
      <div ng-if="person.isTag" ng-bind-html="person.name +' <small>(new)</small>'| highlight: $select.search"></div>
      <div ng-if="!person.isTag" ng-bind-html="person.name + person.isTag| highlight: $select.search"></div>
    <small>
     email: {{person.email}}
     age: <span ng-bind-html="''+person.age | highlight: $select.search"> </span>
    </small>
  </ui-select-choices>
</ui-select>
<p>Selected: {{person.selected}}</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM