在选择菜单中添加所选项目的列表

时间:2018-11-16 15:38:37

标签: angular angular6 angular-components

我发现了这个非常好的Angular搜索菜单示例。

          <ui-select ng-model="ctrl.person.selected" theme="bootstrap">
            <ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
            <ui-select-choices repeat="item in ctrl.people | filter: $select.search">
              <div ng-bind-html="item.name | highlight: $select.search"></div>
              <small ng-bind-html="item.email | highlight: $select.search"></small>
            </ui-select-choices>
          </ui-select>

Working example in web editor

我想扩展示例,并从选择菜单中添加所选项目的列表。您能帮我实现此功能吗?

1 个答案:

答案 0 :(得分:1)

下面的代码将使您的下拉列表成为多个选择,并将显示下拉列表中的选定值列表

 <body class="ng-cloak" ng-controller="DemoCtrl as ctrl">
      Selected:<p ng-repeat="item in ctrl.person.selected"> {{item.name}}</p>

      <form class="form-horizontal">
        <fieldset>
          <legend>ui-select inside a Bootstrap form</legend>    
          <div class="form-group">
            <label class="col-sm-3 control-label">Default</label>
            <div class="col-sm-6">    

              <ui-select ng-model="ctrl.person.selected" theme="bootstrap" multiple="true">
                <ui-select-match placeholder="Select or search a person in the list...">{{$item.name}}</ui-select-match>
                <ui-select-choices repeat="item in ctrl.people | filter: $select.search">
                  <div ng-bind-html="item.name | highlight: $select.search">
                  </div>                  
                  <small ng-bind-html="item.email | highlight: $select.search"></small>
                </ui-select-choices>
              </ui-select>

            </div>
          </div>        
        </fieldset>
      </form>
    </body>

ui-select库提供了用于启用多个选择的多个属性

For detail documentation for ui-select multiple selection click here

希望这会有所帮助。