1

Iam Using Select2 Drop down which is not Filter on Select :-

My Code :-

<div class="form-group">
                                    <script type="text/javascript">
                                            jQuery(document).ready(function($)
                                            {
                                                $("#select-res").select2();
                                        </script>
                                    <select class="form-control select" ng-model="displayName"  id="select-res">
                                        <option data-ng-repeat="objin objs" value="{{obj.displayName}}">{{obj.displayName}}</option>
                                    </select>
                                    <script>
                                        $('#select-res').select2().on('change', function(e) {
                                          var selectedval= $(this).val();
                                           alert(selectedval);
                                           // $("#filterselected").html(selectedval);
                                           // $("#filterselected").val(selectedval+' ');
                                            document.getElementById("filterselected").value = selectedval;
                                        });
                                    </script>
                                      <input id="filterselected" type="text" ng-model="displayName" />
                                </div>

I used data-ng-model="displayName" for Two Way Binding

Filter Code :-

<div data-ng-repeat="obj in objs | filter:displayname" >
       Results ....
</div>

The Options i Selected in Select2 Drop Down Is Not Being Input For Filter Parameter .

I have written the Selected Value in to a Text Box With data binding as ng-model ="displayName" but Not Filtering :-(

2 Answers 2

1

Rather than using select2 library with you should use it angular version which ui-select2

Which provides better binding while dealing with angular scope. As you want to bind change event here you could simply use ng-change angular native directive.

Markup

<select ui-select2 ng-model="number" data-placeholder="Pick a number" ng-change="changeSelect()">
    <option value=""></option>
    <option value="one">First</option>
    <option value="two">Second</option>
    <option value="three">Third</option>
</select>
Sign up to request clarification or add additional context in comments.

6 Comments

Could You Please Send me Some reference Url for ui-select2 .
@PRASAD look at this plunkr plnkr.co/edit/4spbdn?p=info & this is github link github.com/angular-ui/ui-select2
One Question Would it Support Update Operation .. I mean When the Values Selected at the @ Post Operation Would Show as Selected when Edited Right Or Do we need some Coding Magic ?
HI Pankaj I just Posted the Link in Our discussion Window Please take a Look
|
1

Trouble can be, that jquery widgets can append additional input elements breaking angular linking. If so i can suggest 2 solutions to try:

  1. use angular-ui/ui-select instead select2
  2. if you refuse it somewhat, use angular scopes $apply method to let angular know that something changed. I don't know if your piece of html is under controller, if yes you can just call $apply("displayName = '"+selectedval+"'") in your onchange handler

there could also be many other causes, for example form and filter is on different scopes

2 Comments

Could You Please Send me Some reference Url for ui-select2 .

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.