Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:06:38+00:00 2026-06-14T00:06:38+00:00

Two way Databinding with AngularJS + Angular-UI Select2 with Ajax functionality. I created a

  • 0

Two way Databinding with AngularJS + Angular-UI Select2 with Ajax functionality.

I created a directive to implement Select2 dropdown Ajax behavior in Generic way:- (It requires few attributes to get formatResult, formatSelection methods to call, and url).

My problem is how to load value in “Edit Mode”, selected value from dropdown is received in formatselection method, but while loading the screen, I want to load the dropdown from the same value to which it is binded.
Example:-

    <input type="hidden" for="part" class="bigdrop" style="width: 250px" formatresult="partFormatResult" formatselection="partFormatSelection" aurl="/api/Part" search-drop-down ui-select2="configPartSelect2" ng-model="product.SalesPart" data-placeholder="Select Part" ng-change="onPartSelect();" />

    Directive Code

    One23SRCApp.directive('searchDropDown', ['$http', function (http) {
        return function (scope, elm, attrs) {
            var raw = elm[0];
            var fetchFuncName = "fetch" + attrs["uiSelect2"];
            console.log("Directive load pat  " + scope[attrs["ngModel"]]);
            scope[fetchFuncName] = function (queryParams) {
                var result = http.get(queryParams.url, queryParams.data).success(queryParams.success);
                result.abort = function () {
                    return null;
                };
                return result;
            };


            scope[attrs["uiSelect2"]] = {
                minimumInputLength: 3,
              initSelection: scope[attrs["initselection"]],
                ajax: {
                    url: attrs["aurl"],
                    data: function (term, page) {
                            return { params: { isStockable: true, query: term, pageNo: page, pageSize: 20 } };
                    },
                    dataType: 'json',
                    quietMillis: 100,
                    transport: scope[fetchFuncName],
                    results: function (data, page) {
                        var more = (page * 20) <= data.length; // whether or not there are more results available
                        return { results: data, more: more };
                    }
                },
                formatResult: scope[attrs["formatresult"]],
                formatSelection: scope[attrs["formatselection"]],
                dropdownCssClass: "bigdrop" // apply css that makes the dropdown taller
            };

            return { bind: attrs["ngModel"] };
        };

    }]);

//inside controller-
after loading of data
   $("#partDD").select2("val", product.SalesPart);
//$scope.partInitSelection definition.
    $scope.partInitSelection = function (element, callback) {
        if (! $scope.PartList) {
            $scope.PartList = [$scope.product.SalesPart];
        } else {
            $scope.PartList.push($scope.product.SalesPart);
        }
        callback($scope.product.SalesPart);
    };

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:06:39+00:00Added an answer on June 14, 2026 at 12:06 am

    Fixed it finally:-
    As i kept configuration object in scope[attrs[“uiSelect2”]],
    I called the .ajax.data method of above configuration object each time I load data.

    scope[attrs["uiSelect2"]].ajax.results(product.SalesPart.text, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have implement a scenario which involves two way communication between child and parent
AngularJS uses two-way client side data binding ( from AngularJS Developers guide ): Has
I need a two way databinding between a checkbox and a char field in
I have what I believe should be simple two-way databinding in WPF setup, but
I need a BindingList in my UI to provide two-way databinding between my collection
I have yet to find a nice way to do two way databinding in
How does two-way databinding work in Silverlight when the data source object's properties don't
Two way binding does not work on my custom control with the following internals:
Is there a way to fire a two way data bind when the key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.