【问题标题】:How can I get all the selected values in a ui-select multiple in angular如何获取 ui-select multiple in angular 中的所有选定值
【发布时间】:2016-10-20 16:16:13
【问题描述】:

我有以下角度的 ui-select 代码,我想获取所有选定的值以便将它们放入字符串中。选择效果很好 我可以选择产品,但我无法获得我选择的值

<ui-select multiple ng-model="multipleDemo.selectedProducts" theme="bootstrap" ng-disabled="disabled">
                  <ui-select-match class="ui-select-match" placeholder="Επιλογή προϊόντος...">{{$item.name}}</ui-select-match>
                  <ui-select-choices class="ui-select-choices" repeat="product in products | propsFilter: {name: $select.search}">
                    <div ng-bind-html="product.name | highlight: $select.search"></div>
                  </ui-select-choices>
                </ui-select>

在我的控制器中

$scope.multipleDemo = {};
$scope.multipleDemo.selectedProducts = [];

如果我写一个这样的 div

 </div>
                <div>{{multipleDemo.selectedProducts}}</div>
            </div>

然后我在这个 div 中看不到任何内容。 有人可以帮忙吗?

【问题讨论】:

  • 有人知道这件事吗?

标签: angularjs ui-select


【解决方案1】:

我根据您问题中的代码创建了this Fiddle,这似乎有效。不过,我看不出你的代码有什么明显的问题。

控制器如下:

app.controller("myCtrl", function($scope) {  
  $scope.products = [
    {id:1, name:'Apple'},
    {id:2, name:'Banana'},
    {id:3, name:'Carrot'}
  ];

  $scope.multipleDemo = {};
  $scope.multipleDemo.selectedProducts = [];
});

和 HTML:

<div ng-app="app" ng-controller="myCtrl">
  <ui-select multiple ng-model="multipleDemo.selectedProducts" theme="bootstrap" ng-disabled="disabled">
    <ui-select-match class="ui-select-match" placeholder="Επιλογή προϊόντος...">{{$item.name}}</ui-select-match>
     <ui-select-choices class="ui-select-choices" repeat="product in products | propsFilter: {name: $select.search}">
      <div ng-bind-html="product.name | highlight: $select.search"></div>
    </ui-select-choices>
  </ui-select>
  <div>
    Selected: {{multipleDemo.selectedProducts}}
  </div>
</div>

另外我必须在模块上定义一个propsFilter:

app.filter('propsFilter', function() {
  ...
});

并确保 ngSanitize 被包含为依赖项:

var app = angular.module('app', ['ui.select', 'ngSanitize']);

【讨论】:

    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 2019-11-12
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多