0

Using angularjs here.

I am using ui-select for allowing the user to select multiple values as:

<div class="form-group" ng-repeat="(name, data) in usersets" ng-class="{ 'has-error': form[inputName + $index].$invalid && submitted }">
   <ui-select name="{{inputName + $index}}" class="btn m-grid-col-md-3" ng-model="data.value" theme="bootstrap">
        <ui-select-match placeholder="data">{{data.value}}</ui-select-match>
        <ui-select-choices repeat="data in data.userValue | filter: $select.search track by $index">
            <div ng-bind-html="data"></div>
        </ui-select-choices>
    </ui-select>
</div>  

I have used the below line to bind the UI select to an array so that it can show all set of options when user starts to type in it.

<ui-select-choices repeat="data in data.userValue | filter: $select.search track by $index">

My issue is because some changes data.userValue above is not returning an array but just a single string value.

If I try to use the same code above I get error on console as:

[ui.select:items] Expected an array but got 'myString'

'myString' is the string returned from data.userValue

Could anyone point me as to what changes do I need to make above to make it accept a single string instead of an array.

Thanks

2
  • What is the value of data.userValue? If it's a comma-delimited list (or something similar) you could easily convert it to an array in your controller and use the array instead. Commented Aug 13, 2019 at 14:19
  • It is no an array. It just a string ex "myString". This all is a part of directive. Is it possible to convert this to array in html only? Commented Aug 13, 2019 at 14:26

1 Answer 1

1

The ng-repeat collection must be an array or an object.

As per your comment : It is no an array. It just a string ex "myString". This all is a part of directive. Is it possible to convert this to array in html only?

Try this

repeat="data in [data.userValue]

Sign up to request clarification or add additional context in comments.

1 Comment

Ramesh, can you also look at my post stackoverflow.com/questions/57482810/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.