1

I'm trying to figure out the best way to initialize select2 drop down lists in Angular.JS.

Currently all of my html views that contain forms are using the same controller, this raises the obvious question "what if want a drop down list on a page with a custom controller?"

Can anyone think of a more elegant way to initialize my drop down lists?

Below are my HTML view and Forms Controller.

Form.html

    <div class="form-group">
                        <label class="col-md-3 control-label">Model *</label>
                        <div class="col-md-4">
                            <select ng-model="form.Model" class="form-control DDL">
                                <option ng-repeat="item in modelDDL" value="{{item.id}}">{{item.text}}</option>
                            </select>
                            <span class="help-block">

                            </span>
                        </div>
                    </div>

<script>
    $(".DDL").select2();
</script>

FormsController.js:

     //get values for dropdown lists
        $http.get('http://localhost:2982/api/menu?type=model').
  then(function (response) {
      $scope.modelDDL = response.data;

1 Answer 1

1

I would use https://github.com/angular-ui/ui-select then you can use ng-model and then I would use dependency injection with a service that gets the model data. You can use DI in any controller then.

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

1 Comment

ui-select is definitively the best choice out there

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.