使用select2 AngularJS获取选定的标签文本

时间:2014-07-23 09:37:40

标签: angularjs tags selected ui-select2

如何使用angularjs为用户选择多个标签,并考虑以下代码段

标记

<input type="hidden" ui-select2="select2Options" ng-model="list_of_string" style="width:100%" />
                                <small>hint: start to type with  a</small>

角度范围

$scope.list_of_string = [];

$scope.select2Options = {
    data: function() {
        api.categories().then(function(response) {
            $scope.data = response;
        });

        return {'results': $scope.data};
    },
    'multiple': true,
    formatResult: function(data) {

        return data.text;
    },
    formatSelection: function(data) {
        return data.text;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试将<input .../>更改为<select> </select>

喜欢

<select multiple ui-select2 ng-model="list_of_string" style="width: 100%">
    <option ng-repeat="option in data">{{option.text}}</option>
</select>